使用微软提供的CImage类,
#include <atlimage.h>
CImage image;
image.Create(nWidth, nHeight, nBitPerPixel);
BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
ReleaseDC(NULL, hdcSrc);
image.ReleaseDC();
image.Save(CsAllImagePath.GetBuffer(), Gdiplus::ImageFormatPNG);//ImageFormatJPEG
public static string getScreen() { string Opath = @"C:\LogMessage\Pic"; string photoname = DateTime.Now.ToString("yyyyMMddHHmmss"); string path1 = Opath + DateTime.Now.ToShortDateString(); string file = Opath + "//" + photoname + ".jpg"; Image _img = null; Bitmap myImage = null; if (!Directory.Exists(Opath)) Directory.CreateDirectory(Opath); try { Screen scr = Screen.PrimaryScreen; Rectangle rc = scr.Bounds; int iWidth = rc.Width; int iHeight = rc.Height; myImage = new Bitmap(iWidth, iHeight); Graphics gl = Graphics.FromImage(myImage); gl.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight)); _img = myImage; _img.Save(file, System.Drawing.Imaging.ImageFormat.Jpeg); //} } catch { } return file; }
我正在做的一个项目里面的代码,截屏是没问题的,不过是截整个屏幕
试了,同样不清楚,比如VS里的代码看起来会有一点背景,很难看。而PrtSrc键出来的就很清楚。而且这段代码没法截超过屏幕大小的图,我的截图有超过5000*5000的,现在用PrintWindow可以截到,就是不清楚,只是不知道这个截图的参数能不能调
@沧海一杰: gl.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
这条语句就是截图的参数 ,可以调的