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

Bitmap.LockBits 是否“固定"?位圖進入內存?

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

問題描述

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

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

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 不會以任何方式幫助您訪問位圖的數據,因為固定此對象只會阻止托管對象四處移動(位圖對象)(并被垃圾收集).

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 結構的包裝.它不會將數據保存在您必須固定的任何托管數組中,它只是管理 GDI+ 位圖對象的本機句柄.因為 Bitmap.LockBits 是一種告訴這個位圖你有興趣訪問它的內存的方式,它只是一個關于 GdipBitmapLockBits 函數的包裝器.因此,您需要調用它更多地與您使用 GDI+ 位圖的事實有關,而不是與您在使用 GC 的托管環境中工作的事實有關.

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,您應該能夠通過BitmapData.Scan0 使用指針訪問它的內存——它是數據第一個字節的地址.只要您不訪問 BitmapData.Scan0 + Height * Stride 后面的內存,您就不應該有問題.

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.

這篇關于Bitmap.LockBits 是否“固定"?位圖進入內存?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 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 中創建重復的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構建數據庫驅動的菜單)
主站蜘蛛池模板: 一区二区三区在线观看视频 | 三级中文字幕 | 亚洲va视频 | 精品日韩在线 | 午夜av片 | 欧美一级网站 | 免费的av | 国产日本在线 | 艳妇诱春(第5部分)(h) | 久久久九九 | 一区二区三区成人 | 91av免费| 三级在线观看 | 视频一区二区在线播放 | 放几个免费的毛片出来看 | 鲁鲁鲁鲁鲁鲁鲁777777 | 日韩免费看片 | 色偷偷网站 | 日韩欧美专区 | 欧美极品在线 | 91调教视频 | 黄色免费视频网站 | 午夜激情在线观看 | 特级丰满少妇一级aaaa爱毛片 | 欧美日韩精品在线 | 欧美日韩中文字幕 | 欧美激情综合五月色丁香 | 欧美精品在线播放 | 久久888| 国产麻豆一区二区三区 | 免费淫片| 日本欧美亚洲 | 国产精品免费看 | 成人高清视频在线观看 | 欧美www| 91久久精品视频 | 一区在线观看 | 人人看人人草 | 五月婷婷开心 | 91导航| 亚洲一区免费观看 |