怎样将一个尺寸比较大的控件保存成Bitmap
我想把一个大的控件(在它的Parent中不能显示完全,在设置了AutoScroll属性之后可以利用拖动滚动条查看这个控件的全部)保存成一个bitmap,我试过
DrawToBitmap(),但是只能保存下当前可见的那个矩形框,请问怎样才能保存整个控件?
谢谢!!!
------解决方案--------------------DrawToBitmap()有重载吧?
不过要是GDI+画图的话,那直接保存画布就可以了
------解决方案--------------------给你一个参考:
[DllImport( "user32.dll ", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport( "gdi32.dll ", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
public Bitmap DrawToBitmap(Control control)
{
int width = control.DisplayRectangle.Width;
int height = control.DisplayRectangle.Height;
Bitmap image = new Bitmap(width, height);
using (Graphics wrapper = Graphics.FromImage(image))
{
IntPtr wParam = wrapper.GetHdc();
SendMessage(control.Handle, 0x317, wParam, (IntPtr)30);
wrapper.ReleaseHdcInternal(wParam);
}
return image;
}