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

C# 從 System.Drawing.Bitmap 高效獲取像素數據

C# Getting the pixel data efficiently from System.Drawing.Bitmap(C# 從 System.Drawing.Bitmap 高效獲取像素數據)
本文介紹了C# 從 System.Drawing.Bitmap 高效獲取像素數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 HDD 上有幾個 (~2GB) 原始 24bpp RGB 文件.現在我想檢索它的一部分并將其縮放到所需的大小.
(唯一允許的比例是 1, 1/2, 1/4, 1/8, ..., 1/256)

I have several (~2GB) raw 24bpp RGB files on HDD. Now I want to retrieve a portion of it and scale it to the desired size.
(The only scales allowed are 1, 1/2, 1/4, 1/8, ..., 1/256)

所以我目前正在將感興趣的矩形中的每一行讀取到一個數組中,這給我留下了一個高度正確但寬度錯誤的位圖.

So I'm currently reading every line from the rectangle of interest into an array, which leaves me with a bitmap which has correct height but wrong width.

下一步,我將從新創建的數組中創建一個位圖.
這是通過使用指針完成的,因此不涉及數據復制.
接下來我在 Bitmap 上調用 GetThumbnailImage,它會創建一個具有正確尺寸的新位圖.

As the next step I'm creating a Bitmap from the newly created array.
This is done with by using a pointer so there is no copying of data involved.
Next I'm calling GetThumbnailImage on the Bitmap, which creates a new bitmap with the correct dimensions.

現在我想返回新創建的位圖的原始像素數據(作為字節數組).但是為了實現這一點,我目前正在使用 LockBits 將數據復制到一個新數組中.

Now I want to return the raw pixel data (as a byte array) of the newly created bitmap. But to achieve that I'm currently copying the data using LockBits into a new array.

所以我的問題是:有沒有辦法在不復制的情況下將像素數據從位圖中獲取到字節數組中?

類似于:

var bitmapData = scaledBitmap.LockBits(...)
byte[] rawBitmapData = (byte[])bitmapData.Scan0.ToPointer()
scaledBitmap.UnlockBits(bitmapData)
return rawBitmapData 

我很清楚這行不通,這只是我想要實現的目標的一個例子.

I'm well aware that this doesn't work, it is just an example to what I basically want to achieve.

推薦答案

我認為這是您最好的選擇.

I think this is your best bet.

var bitmapData = scaledBitmap.LockBits(...);
var length = bitmapData.Stride * bitmapData.Height;

byte[] bytes = new byte[length];

// Copy bitmap to byte[]
Marshal.Copy(bitmapData.Scan0, bytes, 0, length);
scaledBitmap.UnlockBits(bitmapData);

如果你想傳遞一個字節[],你必須復制它.

You have to copy it, if you want a pass around a byte[].

您不必刪除已分配的字節,只需在完成后處理原始 Bitmap 對象,因為它實現了 IDisposable.

You don't have to delete the bytes that were allocated, you just need to Dispose of the original Bitmap object when done as it implements IDisposable.

這篇關于C# 從 System.Drawing.Bitmap 高效獲取像素數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創建重復的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 99精品免费视频 | 精品粉嫩aⅴ一区二区三区四区 | 91免费小视频 | 999久久久久久久久6666 | 一区二区三区 在线 | 亚洲国产精品99久久久久久久久 | 全免费a级毛片免费看视频免 | 欧美黄色一级毛片 | 老司机67194精品线观看 | 色偷偷噜噜噜亚洲男人 | 亚洲国产成人av | 成人av免费 | 中文字幕高清av | 男女羞羞视频在线看 | 中文字幕福利视频 | 国产成人综合一区二区三区 | 日韩福利在线观看 | 男女啪啪网址 | 欧美一区视频在线 | 99国产精品久久久 | 成人黄在线观看 | 久久国内精品 | 国产精品二区三区 | 欧美一区二区三区视频在线观看 | chengrenzaixian| k8久久久一区二区三区 | 日韩成人精品在线观看 | 日韩一区二区三区在线观看 | 中文字幕91av | 成人在线激情 | 久久中文字幕一区 | av黄色免费在线观看 | 国产xxxx搡xxxxx搡麻豆 | 久久成人精品 | 欧产日产国产精品国产 | 成人超碰| 国产精品视频一区二区三区四区国 | 亚洲欧美综合精品另类天天更新 | 免费久久久 | 日日日操| 精品久久久久久久久久久久 |