久久久久久久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ū)動的菜單)
主站蜘蛛池模板: 欧美精品在线一区二区三区 | 欧美九九 | 蜜桃特黄a∨片免费观看 | 亚洲综合一区二区三区 | 亚洲精品福利在线 | 日韩一区和二区 | 日韩精品一区二区三区中文在线 | 日本久久精品视频 | 精品1区 | 亚洲品质自拍视频网站 | 成人精品国产免费网站 | 香蕉国产在线视频 | 国产亚洲精品久久久久久牛牛 | 国产91丝袜 | 日韩欧美中文 | 国产精品日本一区二区不卡视频 | 欧美日韩中文字幕 | 91视频免费 | 日日摸日日添日日躁av | 日韩欧美成人一区二区三区 | 欧美黄页 | 欧美性大战久久久久久久蜜臀 | 国产午夜精品视频 | 日韩欧美视频在线 | 在线成人免费视频 | 亚洲精品免费在线观看 | 免费视频二区 | 久久久91精品国产一区二区精品 | 一区二区三区亚洲视频 | www国产成人免费观看视频,深夜成人网 | 高清人人天天夜夜曰狠狠狠狠 | 日韩欧美在线不卡 | 国产精品a久久久久 | 亚洲欧美日韩中文字幕一区二区三区 | 国产精久久久久久 | 久久久精品网站 | 国产一二三区精品视频 | 久久精品色欧美aⅴ一区二区 | 91se在线 | 精品久久久久久一区二区 | 国产情侣在线看 |