久久久久久久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ì)邊框)
主站蜘蛛池模板: 亚洲精品一区中文字幕乱码 | 国产精品成人一区 | 成人在线视频观看 | 日日操夜夜操视频 | 国产欧美精品一区二区色综合朱莉 | 欧美日韩在线一区二区 | 国产成人精品一区二区三区在线观看 | 日韩在线视频一区 | 精品日韩电影 | 久久久久久久久久久福利观看 | 日韩视频三区 | 最新免费黄色网址 | 午夜视频在线播放 | av中文网| 久久男人 | 亚洲精品久 | 日韩在线免费视频 | 国产a级黄色录像 | 国产精品亚洲一区二区三区在线观看 | 中文无码日韩欧 | 香蕉久久a毛片 | 国产一区二区在线播放 | 日韩福利在线 | 国产精品毛片一区二区在线看 | 99久久精品免费看国产小宝寻花 | 九九天堂网 | 人人人人爽 | 午夜小视频在线播放 | 国产精品国产三级国产aⅴ中文 | 国产专区在线 | 成人久久久 | 亚洲精品区 | 日韩一二三区视频 | 国产精品国产精品国产专区不蜜 | 在线看黄免费 | 狠狠色综合网站久久久久久久 | 欧美精品久久久久 | 免费在线播放黄色 | 91av在线电影 | 久久99精品视频 | 亚洲福利一区二区 |