GDI +中发生了一般错误。 [英] A generic error occurred in GDI+.

查看:99
本文介绍了GDI +中发生了一般错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将intptr转换为位图时显示错误



like



发生一般性错误GDI +。



我的尝试:



when i convert intptr to bitmap it show error

like

A generic error occurred in GDI+.

What I have tried:

IntPtr hbitmap = IntPtr.Zero;
m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
       
hbitmap = m_SecuBSP.CaptureWindowOption.FingerWindow;
Image img = Image.FromHbitmap(hbitmap);

推荐答案

PictureBox返回的句柄。句柄不是 PictureBox 中显示的位图的句柄( HBITMAP )但是控件窗口句柄( HWND )。



要从PictureBox获取图像,只需使用

The handle returned by PictureBox.Handle is not the handle of the bitmap shown in the PictureBox (a HBITMAP) but the controls window handle (a HWND).

To get the image from the PictureBox just use
Image img = pictureBox1.Image;



如果您需要获取该图像的位图句柄,请创建一个新位图


If you need to get the bitmap handle for that image, create either a new bitmap

Bitmap bmp = new Bitmap(pictureBox1.Image);
IntPtr hBitmap = bmp.GetHbitmap();

或转换图像

or cast the Image

Bitmap bmp = (Bitmap)pictureBox1.Image;
IntPtr hBitmap = bmp.GetHbitmap();


这篇关于GDI +中发生了一般错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆