我需要透明度使ARGB透明度,具有2個像素:如何使用按位運算符
pixel1: {A, R, G, B} - foreground pixel
pixel2: {A, R, G, B} - background pixel
A,R,G,B是字節值
每個顏色由字節表示的值
現在我計算透明度:
newR = pixel2_R * alpha/255 + pixel1_R * (255 - alpha)/255
newG = pixel2_G * alpha/255 + pixel1_G * (255 - alpha)/255
newB = pixel2_B * alpha/255 + pixel1_B * (255 - alpha)/255
,但實在是太慢了 我需要位運算符(AND,OR,XOR,否定,BIT MOVE)做
我想這樣做,在Windows Phone 7 XNA
- - 附帶的C#代碼---
public static uint GetPixelForOpacity(uint reduceOpacityLevel, uint pixelBackground, uint pixelForeground, uint pixelCanvasAlpha)
{
byte surfaceR = (byte)((pixelForeground & 0x00FF0000) >> 16);
byte surfaceG = (byte)((pixelForeground & 0x0000FF00) >> 8);
byte surfaceB = (byte)((pixelForeground & 0x000000FF));
byte sourceR = (byte)((pixelBackground & 0x00FF0000) >> 16);
byte sourceG = (byte)((pixelBackground & 0x0000FF00) >> 8);
byte sourceB = (byte)((pixelBackground & 0x000000FF));
uint newR = sourceR * pixelCanvasAlpha/256 + surfaceR * (255 - pixelCanvasAlpha)/256;
uint newG = sourceG * pixelCanvasAlpha/256 + surfaceG * (255 - pixelCanvasAlpha)/256;
uint newB = sourceB * pixelCanvasAlpha/256 + surfaceB * (255 - pixelCanvasAlpha)/256;
return (uint)255 << 24 | newR << 16 | newG << 8 | newB;
}
將分割形式255更改爲256改進了很多代碼。調試模式下8 FPS至14 FPS。 – 2011-03-17 09:24:22