久久久久久久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ù)庫驅動的菜單)
主站蜘蛛池模板: 色综合av| 欧美日韩在线一区二区三区 | www.成人.com| 国产91精品网站 | 欧美一级毛片在线播放 | 欧美视频三区 | 人人干人人草 | 国产精品欧美一区喷水 | 亚洲一区二区免费视频 | 99一区二区 | 欧美日韩在线一区二区三区 | 在线欧美| 国产欧美综合在线 | 久久亚洲免费 | 国产91久久久久久 | 欧美精品一二三区 | 国产一级片一区二区三区 | 国产99视频精品免费播放照片 | 亚洲一区在线播放 | 日本一区二区在线视频 | 黄视频免费 | 国产特级毛片 | 亚洲高清在线观看 | 天堂色综合 | 99精品一区二区 | 青青草综合网 | 777zyz色资源站在线观看 | www..com18午夜观看 | 国产精品高清一区二区三区 | 日韩亚洲一区二区 | 美国一级片在线观看 | 日韩一区二区精品 | 亚洲不卡在线观看 | 免费观看成人鲁鲁鲁鲁鲁视频 | 免费在线h视频 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 91传媒在线观看 | 国产在线一区二区三区 | 久草视频观看 | 亚洲日日夜夜 | 午夜三级在线观看 |