2010-06-03 157 views
0

我的項目我想使用EmguCV庫,但EmguCV的功能無法處理Bitmap對象,所以我必須將Bitmap轉換爲其他類型,Intptr是一個選擇,但我真不知道如何編碼,老鄉代碼是抽象的,從我的項目是這樣的:如何將位圖轉換爲intptr C#

Bitmap bmp = new Bitmap(e.width, e.height, 
    System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
System.Drawing.Imaging.BitmapData data = 
    bmp.LockBits(new Rectangle(0, 0, e.width, e.height), 
     System.Drawing.Imaging.ImageLockMode.ReadWrite, 
     System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
int dataLength = e.width * e.height * 3; 
Win32.memcpy(data.Scan0, (IntPtr)e.data, (uint)dataLength); 
convertBitmapToIntptr(bmp); 

我怎麼能在這個功能convertBitmapToIntptr(bmp)代碼?

+0

不太確定你在問什麼? – 2010-06-03 01:19:02

+0

你在尋找GetHbitmap()嗎? http://msdn.microsoft.com/en-us/library/1dz311e4.aspx – 2010-06-03 13:40:31

回答

0

你想在一個類來包裝這個....

我已經做到了這一點,並把它稱爲「FastBitmap」,你可以在構造函數中鎖定,獲得了PTR,並添加方法一起工作在PTR

1

這可能是一個老問題,但如果你正在使用EmguCV,位圖轉換的IntPtr可以做(爲2.4.2版本),如下面的例子:

Bitmap bitmap = new Bitmap("pathToBitmapFile"); 

Image<Bgr,byte> image = new Image<Bgr,byte>(bitmap); 

IntPtr = image.Ptr; 

EmguCV Documentation