[英]Get raw pixel value in bitmap image
如何獲取位圖圖像中的每像素位數? 例如,如果像素x=24
& y=45
具有RGB 123
, 212
, 112
,以便它必須返回1111011
, 11010100
, 1110000
。
您的問題並非特定於像素,基本上需要獲取字節的位:
您可以使用靜態擴展:
public static string ToBitString(this byte b)
{
StringBuilder sb = new StringBuilder(8);
for (int i = 7; i >= 0; i--)
{
sb.Append((b & (1 << i)) > 0 ? '1' : '0');
}
return sb.ToString();
}
並使用:
byte bt = 120;
Console.WriteLine(bt.ToBitString());
// outputs 01111000
在你的情況下:
Color c = ...;
string s = ((byte) c.B).ToBitString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.