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

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

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

問(wèn)題描述

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

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)建的帶有像素(紅色、綠色、藍(lán)色、白色)的非常簡(jiǎn)單的 2x2 PNG 圖像測(cè)試了此圖像.由于格式的原因,我希望 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é)似乎交換了嗎?順便說(shuō)一句,當(dāng)我將圖像直接用于 Image.Source 時(shí),如下所示,圖像顯示正確.那我的錯(cuò)是什么?

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"/>

推薦答案

像素?cái)?shù)據(jù)為 ARGB,1 字節(jié)為 alpha,1 為紅色,1 為綠色,1 為藍(lán)色.Alpha 是最高有效字節(jié),藍(lán)色是最低有效字節(jié).在像您和許多其他機(jī)器一樣的小端機(jī)器上,小端首先存儲(chǔ),因此字節(jié)順序是 bb gg rr aa.所以 0 0 255 255 等于藍(lán)色 = 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.

當(dāng)您將 bd.Scan0 轉(zhuǎn)換為 int*(指向整數(shù)的指針)時(shí),此字節(jié)序詳細(xì)信息將消失,因?yàn)檎麛?shù)也以小字節(jié)序存儲(chǔ).

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.

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

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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 add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構(gòu)建數(shù)據(jù)庫(kù)驅(qū)動(dòng)的菜單)
主站蜘蛛池模板: 亚洲免费在线播放 | 日韩精品毛片 | 免费一级全黄少妇性色生活片 | 国产www在线观看 | 久久综合社区 | 美女视频一区二区 | 国产综合亚洲精品一区二 | 亚洲一级片在线观看 | 伊人久久影视 | 国产欧美精品一区二区三区 | 国产精品久久久久久久久久久久午夜片 | 成人网战| 国产理论在线观看 | 波多野结衣在线观看一区二区 | 天天操夜夜 | 一级特黄妇女高潮 | 久久亚洲一区二区 | 欧美日韩一区在线观看 | 国产成人午夜高潮毛片 | 日本黄色一级视频 | 在线观看二区 | 天天视频国产 | 青青艹在线视频 | 国产日韩综合 | 久久福利网| 国产日韩欧美亚洲 | www.久久久久 | 日韩城人网站 | 成人福利视频在线观看 | 国产精品国产精品国产专区不片 | 国产又粗又猛 | 欧美日韩黄| 日韩不卡一区二区 | 久久成人一区 | 日韩精品中文字幕在线观看 | 一区二区视频在线 | 天天爽夜夜爽 | 国产成人小视频 | 午夜精品久久久久久久99 | 免费黄色av | 国产日韩欧美综合 |