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

Bitmap.LockBits 是否“固定"?位圖進(jìn)入內(nèi)存?

Does Bitmap.LockBits quot;pinquot; a bitmap into memory?(Bitmap.LockBits 是否“固定?位圖進(jìn)入內(nèi)存?)
本文介紹了Bitmap.LockBits 是否“固定"?位圖進(jìn)入內(nèi)存?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我最近經(jīng)常使用鎖定位圖,并且不斷收到試圖訪問無效內(nèi)存"錯誤.這主要是因為位圖已在內(nèi)存中移動.有些人使用 GCHandle.Alloc() 在 CLR 中分配內(nèi)存并固定它.Bitmap.LockBits() 做同樣的事情嗎?我不明白鎖定"內(nèi)存和固定"內(nèi)存之間的區(qū)別.您能否解釋一下術(shù)語和差異(如果有)?

I'm using locked bitmaps a lot recently, and I keep getting "attempted to access invalid memory" errors. This is mostly because the bitmap has been moved in memory. Some people using GCHandle.Alloc() to allocate memory in the CLR and pin it. Does Bitmap.LockBits() do the same? I don't understand the difference between "locking" memory and "pinning" memory. Can you also explain the terminology and the differences if any?

推薦答案

GCHandle.Alloc 是一種更通用的方法,它允許您為任何托管對象分配一個句柄并將其固定在內(nèi)存中(或不).固定內(nèi)存可防止 GC 移動它,這在您必須將某些數(shù)據(jù)(例如數(shù)組)傳遞給非托管代碼時特別有用.

GCHandle.Alloc is a more generic method, that allows you to allocate a handle to any managed object and pin it in memory (or not). Pinning memory prevents GC from moving it around, which is especially useful when you have to pass some data, for example an array, to a unmanaged code.

GCHandle.Alloc 不會以任何方式幫助您訪問位圖的數(shù)據(jù),因為固定此對象只會阻止托管對象四處移動(位圖對象)(并被垃圾收集).

GCHandle.Alloc will not help you access bitmap's data in any way, because pinning this object will just prevent the managed object from moving around (the Bitmap object) (and being garbage collected).

然而,位圖是對原生 GDI+ 的 BITMAP 結(jié)構(gòu)的包裝.它不會將數(shù)據(jù)保存在您必須固定的任何托管數(shù)組中,它只是管理 GDI+ 位圖對象的本機(jī)句柄.因為 Bitmap.LockBits 是一種告訴這個位圖你有興趣訪問它的內(nèi)存的方式,它只是一個關(guān)于 GdipBitmapLockBits 函數(shù)的包裝器.因此,您需要調(diào)用它更多地與您使用 GDI+ 位圖的事實(shí)有關(guān),而不是與您在使用 GC 的托管環(huán)境中工作的事實(shí)有關(guān).

Bitmap however is a wrapper around native GDI+'s BITMAP structure. It doesn't keep data in any managed array that you would have to pin, it just managed a native handle to GDI+ bitmap object. Because of that Bitmap.LockBits is a way of telling this bitmap that you are interested in accessing it's memory, and it's just a wrapper around GdipBitmapLockBits function. So your need of calling it has more to do with the fact that you are working with GDI+ bitmaps than with the fact, that you're working in managed environment with GC.

一旦您使用了LockBits,您應(yīng)該能夠通過BitmapData.Scan0 使用指針訪問它的內(nèi)存——它是數(shù)據(jù)第一個字節(jié)的地址.只要您不訪問 BitmapData.Scan0 + Height * Stride 后面的內(nèi)存,您就不應(yīng)該有問題.

Once you have used LockBits you should be able to access it's memory using pointers through BitmapData.Scan0 - it's an address of first byte of data. You should not have problems as long, as you do not access memory behind BitmapData.Scan0 + Height * Stride.

完成后記得UnlockBits.

這篇關(guān)于Bitmap.LockBits 是否“固定"?位圖進(jìn)入內(nèi)存?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 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ù)庫驅(qū)動的菜單)
主站蜘蛛池模板: 亚洲在线一区二区三区 | 欧洲一级黄 | 五月天国产视频 | 精品二三区 | 国产中文 | 久久精彩视频 | 超碰精品在线观看 | 日本不卡一区二区三区在线观看 | 亚洲 中文 欧美 日韩 在线观看 | 免费能直接在线观看黄的视频 | 91中文字幕| 国产在视频一区二区三区吞精 | 国产有码 | 午夜一区二区三区 | 亚洲精品一二区 | 91精品国产一区 | 毛片在线看片 | 日韩一区二区三区视频在线观看 | 日韩精品四区 | 欧美a在线看 | 婷婷毛片| 亚洲www啪成人一区二区麻豆 | 国产欧美综合在线 | 日韩成人久久 | 亚洲欧美另类在线观看 | 欧美午夜影院 | 国产成人av免费看 | 国产精品电影网 | 久久99这里只有精品 | 天天爽综合网 | 久久久久久久久久一区二区 | 91伊人网 | 久久久久久亚洲欧洲 | 中文字幕在线第一页 | 日本亚洲欧美 | 久久国产亚洲 | 亚洲电影一级片 | 少妇一级淫片免费放播放 | 成人免费视频网站在线看 | 黄色av观看 | av大片在线观看 |