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

C# 從 System.Drawing.Bitmap 高效獲取像素數(shù)據(jù)

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

問題描述

我在 HDD 上有幾個 (~2GB) 原始 24bpp RGB 文件.現(xiàn)在我想檢索它的一部分并將其縮放到所需的大小.
(唯一允許的比例是 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)

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

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.

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

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.

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

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.

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

類似于:

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

我很清楚這行不通,這只是我想要實現(xiàn)的目標(biāo)的一個例子.

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

推薦答案

我認(rèn)為這是您最好的選擇.

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);

如果你想傳遞一個字節(jié)[],你必須復(fù)制它.

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

您不必刪除已分配的字節(jié),只需在完成后處理原始 Bitmap 對象,因為它實現(xiàn)了 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.

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應(yīng)用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應(yīng)用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細(xì)邊框)
主站蜘蛛池模板: 中文在线字幕免费观看 | 日韩精品久久久久久 | 亚洲综合天堂 | 天天爱天天色 | 色影视 | 日韩高清一区 | 欧美精品三区 | 久久cao | 欧美一级淫片bbb一84 | 黄色一级视频 | 日韩天天操 | 天天爱天天色 | 欧美午夜精品一区二区三区 | 亚洲国产日韩在线 | 国产天天操 | 一区二区三区久久久 | 操操影院 | 四虎官网 | 国产精品福利在线 | 韩日精品视频 | 久久精品综合 | 96看片| 国产亚洲天堂 | 欧美人与野 | 黄色亚洲 | 国产欧美欧洲 | 亚洲高清视频在线观看 | 国产精品美女久久久久av爽 | 婷婷激情综合网 | 伊人国产女 | 亚洲美女毛片 | 久久国产亚洲 | 亚洲免费a | 亚洲黄色在线视频 | 国产小视频在线观看 | 国产亚洲精品成人av久久ww | 青青五月天 | 亚洲视频一区在线观看 | 亚洲成人免费网站 | 国产精品一区二区三区免费 | 在线看亚洲 |