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

PixelFormat.Format32bppArgb 似乎有錯誤的字節(jié)順序

PixelFormat.Format32bppArgb seems to have wrong byte order(PixelFormat.Format32bppArgb 似乎有錯誤的字節(jié)順序)
本文介紹了PixelFormat.Format32bppArgb 似乎有錯誤的字節(jié)順序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我嘗試從位圖(System.Drawing.Bitmap)中獲取所有字節(jié)值.因此我鎖定字節(jié)并復制它們:

I try to get all byte values from a Bitmap(System.Drawing.Bitmap). Therefore I lock the bytes and copy them:

public static byte[] GetPixels(Bitmap bitmap){
    if(bitmap-PixelFormat.Equals(PixelFormat.Format32.bppArgb)){
        var argbData = new byte[bitmap.Width*bitmap.Height*4];
        var bd = bitmap.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
        System.Runtime.InteropServices.Marshal.Copy(bd.Scan0, argbData, 0, bitmap.Width * bitmap.Height * 4);
        bitmap.UnlockBits(bd);
    }
}

我使用在 Photoshop 中創(chuàng)建的帶有像素(紅色、綠色、藍色、白色)的非常簡單的 2x2 PNG 圖像測試了此圖像.由于格式的原因,我希望 argbData 中有以下值:

I tested this Image with a very simple 2x2 PNG image with pixels (red, green, blue, white) that I created in Photoshop. Because of the format, I expected the following values within the argbData:

255 255   0   0    255 0   255   0 
255 0     0 255    255 255 255 255 

但我得到了:

0     0 255 255     0 255   0 255
255   0   0 255   255 255 255 255

但這是一種 BGRA 格式.有人知道為什么字節(jié)似乎交換了嗎?順便說一句,當我將圖像直接用于 Image.Source 時,如下所示,圖像顯示正確.那我的錯是什么?

But this is a BGRA format. Does anybody know why the bytes seems swapped? By the way, when I use the image directly for a Image.Source as shown below, the Image is shown correctly. So what's my fault?

<Image Source="D:/tmp/test2.png"/>

推薦答案

像素數(shù)據(jù)為 ARGB,1 字節(jié)為 alpha,1 為紅色,1 為綠色,1 為藍色.Alpha 是最高有效字節(jié),藍色是最低有效字節(jié).在像您和許多其他機器一樣的小端機器上,小端首先存儲,因此字節(jié)順序是 bb gg rr aa.所以 0 0 255 255 等于藍色 = 0,綠色 = 0,紅色 = 255,alpha = 255.那是紅色.

Pixel data is ARGB, 1 byte for alpha, 1 for red, 1 for green, 1 for blue. Alpha is the most significant byte, blue is the least significant. On a little-endian machine, like yours and many others, the little end is stored first so the byte order is bb gg rr aa. So 0 0 255 255 equals blue = 0, green = 0, red = 255, alpha = 255. That's red.

當您將 bd.Scan0 轉換為 int*(指向整數(shù)的指針)時,此字節(jié)序詳細信息將消失,因為整數(shù)也以小字節(jié)序存儲.

This endian-ness order detail disappears when you cast bd.Scan0 to an int* (pointer-to-integer) since integers are stored little-endian as well.

這篇關于PixelFormat.Format32bppArgb 似乎有錯誤的字節(jié)順序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應用程序 - 如何制作交互式菜單?)
How to add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構建數(shù)據(jù)庫驅動的菜單)
主站蜘蛛池模板: 欧美一级免费看 | 七七婷婷婷婷精品国产 | 91麻豆精品国产91久久久更新资源速度超快 | 日韩精品一区二区三区 | 亚洲伊人久久综合 | 999久久久久久久 | 亚洲综合国产 | 乱码av午夜噜噜噜噜动漫 | 久久精品二区亚洲w码 | 国产乱码精品一区二区三区中文 | 国产精品成人69xxx免费视频 | 久久小视频 | 6080yy精品一区二区三区 | 成人欧美一区二区三区黑人孕妇 | 人人爽日日躁夜夜躁尤物 | 国产乱码精品一区二区三区忘忧草 | 亚洲精品国产a久久久久久 午夜影院网站 | 国产中文区二幕区2012 | 国产精品国产a | 午夜视频免费在线观看 | 久热中文字幕 | 欧美日韩久久久 | 日韩图区 | 日韩国产一区 | 国产精品日韩一区二区 | 日韩高清电影 | 国产色网站 | 国产欧美精品一区二区三区 | 亚洲高清久久 | 狠狠色综合久久丁香婷婷 | 久久久久亚洲精品国产 | 日本欧美在线观看视频 | 精品国产99| 日日噜 | 欧美亚洲国产日韩 | 伊人一区 | 国产福利视频网站 | 日韩精品二区 | 在线亚洲欧美 | 亚洲高清在线观看 | 美女国产一区 |