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

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

c# RGB Values from Bitmap Data(c# 位圖數(shù)據(jù)中的 RGB 值)
本文介紹了c# 位圖數(shù)據(jù)中的 RGB 值的處理方法,對(duì)大家解決問題具有一定的參考價(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ǎn)單地從單個(gè)字節(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);

使用此代碼,您最終會(huì)得到字節(jié)數(shù)組 data,其中填充了 ARGB 格式的圖像數(shù)據(jù),這意味著顏色分量字節(jié)將按 [B, G, R, A].請(qǐng)注意,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 值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 在頂部菜單上滾動(dòng))
C# Console app - How do I make an interactive menu?(C# 控制臺(tái)應(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自動(dòng)化控制桌面應(yīng)用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項(xiàng)周圍的細(xì)邊框)
主站蜘蛛池模板: 91av在线播放| 黄色精品| 国产特级淫片免费看 | 成人午夜在线观看 | 亚洲一区二区三区在线视频 | 成 人 黄 色 片 在线播放 | 欧美福利在线 | 免费黄网站在线观看 | 国产一区在线观看视频 | 免费欧美视频 | 日韩久久久 | 91在线观 | 成年人黄色网址 | 国产成人精品免费视频 | 免费一级黄色 | 无遮挡在线观看 | www.四虎在线| a级片网址 | 亚洲色在线视频 | 黄色日皮视频 | 久久久久久久久久久久久久久久久久久 | 午夜www| 日本免费在线观看 | 久久艹精品 | 国产成人免费在线视频 | 中文字幕少妇 | 日韩一区二区免费视频 | 成人激情片 | 久久亚洲国产精品 | 亚洲日本中文字幕 | 9999精品视频 | 一级看片免费视频 | 好吊妞这里只有精品 | 亚洲福利视频一区 | 欧美一区二区三区在线视频 | 中文字幕亚洲天堂 | 国产精品成人国产乱 | 亚洲自拍偷拍一区 | 国产免费黄色片 | 欧美日韩成人一区二区三区 | 欧美一级淫片免费视频黄 |