久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

c# 位圖數(shù)據(jù)中的 RGB 值

c# RGB Values from Bitmap Data(c# 位圖數(shù)據(jù)中的 RGB 值)
本文介紹了c# 位圖數(shù)據(jù)中的 RGB 值的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我是位圖的新手,每像素使用 16 位Format16bppRgb555

I am new in working with Bitmap and using 16 bits per pixel Format16bppRgb555;

我想從位圖數(shù)據(jù)中提取 RGB 值.這是我的代碼

I want to Extract RGB Values from Bitmap Data. Here is my code

static void Main(string[] args)
    {

        BitmapRGBValues();
        Console.ReadKey();
    }


 static unsafe void BitmapRGBValues()
    {

        Bitmap cur = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format16bppRgb555);
        //Capture Screen
        var screenBounds = Screen.PrimaryScreen.Bounds;
        using (var gfxScreenshot = Graphics.FromImage(cur))
        {
            gfxScreenshot.CopyFromScreen(screenBounds.X, screenBounds.Y, 0, 0, screenBounds.Size, CopyPixelOperation.SourceCopy);
        }

        var curBitmapData = cur.LockBits(new Rectangle(0, 0, cur.Width, cur.Height),
                                 ImageLockMode.ReadWrite, PixelFormat.Format16bppRgb555);


        try
        {
            byte* scan0 = (byte*)curBitmapData.Scan0.ToPointer();

            for (int y = 0; y < cur.Height; ++y)
            {
                ulong* curRow = (ulong*)(scan0 + curBitmapData.Stride * y);

                for (int x = 0; x < curBitmapData.Stride / 8; ++x)
                {

                    ulong pixel = curRow[x];

                    //How to get RGB Values  from pixel;







                }

            }


        }
        catch
        {

        }
        finally
        {
            cur.UnlockBits(curBitmapData);

        }


    }

推薦答案

LockBits 實(shí)際上可以轉(zhuǎn)換您的圖像到所需的像素格式,這意味著不需要進(jìn)一步轉(zhuǎn)換.只需將圖像鎖定為 Format32bppArgb,您就可以簡單地從單個字節(jié)中獲取顏色值.

LockBits can actually convert your image to a desired pixel format, meaning no further conversion should be needed. Just lock the image as Format32bppArgb and you can simply take your colour values from single bytes.

BitmapData curBitmapData = cur.LockBits(new Rectangle(0, 0, cur.Width, cur.Height),
    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
Int32 stride = curBitmapData.Stride;
Byte[] data = new Byte[stride * cur.Height];
Marshal.Copy(curBitmapData.Scan0, data, 0, data.Length);
cur.UnlockBits(curBitmapData);

使用此代碼,您最終會得到字節(jié)數(shù)組 data,其中填充了 ARGB 格式的圖像數(shù)據(jù),這意味著顏色分量字節(jié)將按 [B, G, R, A].請注意,stride 是跳轉(zhuǎn)到圖像下一行的字節(jié)數(shù),因?yàn)檫@總是等于width * bytes per pixel",應(yīng)始終予以考慮.

With this code, you end up with the byte array data, which is filled with your image data in ARGB format, meaning the colour component bytes will be in there in the order [B, G, R, A]. Note that the stride is the amount of bytes to skip to get to a next line on the image, and since this is not always equal to "width * bytes per pixel", it should always be taken into account.

現(xiàn)在你明白了,你可以用它做任何你想做的事......

Now you got that, you can do whatever you want with it...

Int32 curRowOffs = 0;
for (Int32 y = 0; y < cur.Height; y++)
{
    // Set offset to start of current row
    Int32 curOffs = curRowOffs;
    for (Int32 x = 0; x < cur.Width; x++)
    {
        // ARGB = bytes [B,G,R,A]
        Byte b = data[curOffs];
        Byte g = data[curOffs + 1];
        Byte r = data[curOffs + 2];
        Byte a = data[curOffs + 3];
        Color col = Color.FromArgb(a, r, g, b);

        // Do whatever you want with your colour here
        // ...

        // Increase offset to next colour
        curOffs += 4;
    }
    // Increase row offset
    curRowOffs += stride;
}

您甚至可以編輯字節(jié),然后根據(jù)需要根據(jù)它們構(gòu)建新圖像.

You can even edit the bytes, and then build a new image from them if you want.

這篇關(guān)于c# 位圖數(shù)據(jù)中的 RGB 值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應(yīng)用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應(yīng)用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項(xiàng)周圍的細(xì)邊框)
主站蜘蛛池模板: 亚洲精品久久久9婷婷中文字幕 | 99精品视频免费观看 | 国产农村一级片 | 中文字幕亚洲一区二区va在线 | 成人性生交大片 | 日韩av在线一区二区 | 久久精品一区二区三区四区 | 亚洲h色 | 亚洲免费在线 | av网站在线看 | 久久视频免费看 | 黄色毛片一级 | 国产精品毛片一区二区三区 | av影音 | 91精品久久久久久久久 | 成人免费大片黄在线播放 | 97人人爱| 精品日韩 | 黄色毛片在线观看 | 免费高清成人 | 国产精品久久久久久 | 日本一本视频 | 亚洲少妇综合网 | 免费在线黄 | 亚洲欧美国产一区二区三区 | 欧美一区二区在线观看 | 亚洲图片一区二区三区 | 久久精品免费一区二区 | 日韩免费av网站 | 一级做a| 精品免费在线 | 精品福利在线 | 99亚洲精品| 中文字幕高清视频 | 一区免费观看 | 国产一区二区三区免费观看在线 | 日韩一区二区在线观看 | 91久久久久久久久 | 日韩av成人在线 | 一区二区三区四区日韩 | 午夜电影一区二区 |