久久久久久久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(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 日本成人在线播放 | 日韩在线视频观看 | 久久一区二区视频 | 电影午夜精品一区二区三区 | 国产一级影片 | 国产精品久久久久久久久久久免费看 | 国产丝袜av | 成在线人视频免费视频 | 91一区二区三区在线观看 | a级网站 | 一区二区三区四区在线 | 国产黄色大片 | 精品视频一区二区三区在线观看 | 日韩欧美国产一区二区三区 | 国产精品久久 | 欧美一区二区三区视频 | 国产成人精品区一区二区不卡 | 亚洲a视 | 国产精品视频二区三区 | 99精品视频在线观看 | 国产精品亚洲综合 | 国产精品久久久久久婷婷天堂 | 成人精品一区 | 日韩精品一区在线 | 亚洲国产一区二区三区在线观看 | 欧美精品二区三区 | 欧美精品在线免费 | 国产精品一区二区不卡 | 九九九色 | 国产美女一区二区 | 91社区在线观看高清 | 久久综合爱| xxxxxx国产 | 婷婷在线网站 | 成人毛片网站 | 久久久久亚洲精品 | 天天久久| 一区二区三区在线免费看 | 久久免费精品 | 精品96久久久久久中文字幕无 | 国产视频福利一区 |