簡體   English   中英

獲取位圖圖像中的原始像素值

[英]Get raw pixel value in bitmap image

如何獲取位圖圖像中的每像素位數? 例如,如果像素x=24y=45具有RGB 123212112 ,以便它必須返回1111011110101001110000

將文件加載到Bitmap中 ,獲取像素 ,並從中讀取顏色信息,這將為R,G和B中的每一個提供字節。

Bitmap bmp = new Bitmap ("C:\image.bmp");
Color color = bmp.GetPixel(24, 45);
Debug.WriteLine (string.Format ("R={0}, G={1}, B={2}", color.R, color.G, color.B));

請參閱Aliostad的答案,了解如何將其轉換為二進制字符串。 我認為問題並不完全清楚你需要什么。

要獲得每像素位數,請使用此函數:

Image.GetPixelFormatSize(bitmap.PixelFormat) 

欲了解更多信息,你可以閱讀這個答案,以及這個

您的問題並非特定於像素,基本上需要獲取字節的位:

您可以使用靜態擴展:

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM