2013-12-10 21 views

回答

1

爲了得到第一個像素的顏色我會建議你使用:

Color c = wb.GetPixel(0, 0); 

如果你真的想使用的像素陣列和轉換自己,你可以檢查與getPixel函數是怎麼做的,如它是開源的(見WriteableBitmapBaseExtensions.cs at Codeplex),只需更改你如何得到C值你得到這個,它應該做的伎倆:

var c = wb.Pixels[0]; 
var a = (byte)(c >> 24); 


// Prevent division by zero 
int ai = a; 
if (ai == 0) 
{ 
    ai = 1; 
} 

// Scale inverse alpha to use cheap integer mul bit shift 
ai = ((255 << 8)/ai); 
Color theColor = Color.FromArgb(a, 
       (byte)((((c >> 16) & 0xFF) * ai) >> 8), 
       (byte)((((c >> 8) & 0xFF) * ai) >> 8), 
       (byte)((((c & 0xFF) * ai) >> 8))); 
0

可以使用

Color color = bitmap.GetPixel(0,0);