Windows客户端开发--截图并保存为JPG文件
来源:互联网 发布:java检查链表是否有环 编辑:程序博客网 时间:2024/06/08 00:34
JPG和PNG的区别:
PNG is a true color lossless format. In practice it can accomplish a compression on standard photos of a factor of 2-3x with no quality loss with respect to the raw bitmap data.
JPEG is a true color lossy format. Depending on the settings the user can determine the tradeoff between quality and amount of compression, which can usually achieve a compression ratio well above 10x.
何为GetEncoderClsid
CLSID是指windows系统对于不同的应用程序,文件类型,OLE对象,特殊文件夹以及各种系统组件分配一个唯一表示它的ID代码,用于对其身份的标示和与其他对象进行区分。
msdn上有例子:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms533843(v=vs.85).aspx
The function GetEncoderClsid in the following example receives the MIME type of an encoder and returns the class identifier (CLSID) of that encoder. The MIME types of the encoders built into Windows GDI+ are as follows:
image/bmpimage/jpegimage/gifimage/tiffimage/png
介绍类和一些方法:
ImageCodecInfo类
The ImageCodecInfo class provides the necessary storage members and methods to retrieve all pertinent information about the installed image encoders and decoders (called codecs). Not inheritable.
Clsid方法
Gets or sets a Guid structure that contains a GUID that identifies a specific codec.
GetImageEncodersSize
The GetImageEncodersSize function gets the number of available image encoders and the total size of the array of ImageCodecInfo objects that is returned by the GetImageEncoders function.
GetImageEncoders
The GetImageEncoders function gets an array of ImageCodecInfo objects that contain information about the available image encoders.
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid){ UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) { return -1; // Failure } pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) { return -1; // Failure } GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure}
bitmap转为jpg
先介绍几个函数:
Bitmap::FromHBITMAP
The Bitmap::FromHBITMAP method creates a Bitmap object based on a handle to a Windows Graphics Device Interface (GDI) bitmap and a handle to a GDI palette.
Bitmap的save方法
Saves this Image to the specified file, with the specified encoder and image-encoder parameters.
void BitmapToJpg(HBITMAP hbmpImage, int width, int height){ Bitmap *p_bmp = Bitmap::FromHBITMAP(hbmpImage, NULL); CLSID jpgClsid; int result = GetEncoderClsid(L"image/jpeg", &jpgClsid); if(result != -1) std::cout << "Encoder succeeded" << std::endl; else std::cout << "Encoder failed" << std::endl; p_bmp->Save(L"screen.jpg", &pngClsid, NULL); delete p_bmp;}
ScreenCapture
先介绍几个函数:
CreateCompatibleDC
The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.
CreateCompatibleBitmap
The CreateCompatibleBitmap function creates a bitmap compatible with the device that is associated with the specified device context.
BitBlt
The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
bool ScreenCapture(int x, int y, int width, int height){ HDC hDc = CreateCompatibleDC(0); HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height); SelectObject(hDc, hBmp); BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY); BitmapToJpg(hBmp, width, height); DeleteObject(hBmp); DeleteDC(hDc); return true;}
- Windows客户端开发--截图并保存为JPG文件
- windows截图保存为文件
- C++截图并保存为文件
- Windows 实现桌面截屏并保存为.jpg
- VC屏幕截图并保存为bmp、jpg、png等格式文件
- VC屏幕截图并保存为bmp、jpg、png等格式文件
- WinCE实现屏幕截图并保存为BMP文件
- VC屏幕截图并保存为bmp文件
- VC屏幕截图并保存为bmp文件
- 【iOS开发-截图】截图并保存相册
- 屏幕截图保存为文件
- 二进制图片保存为jpg文件
- Java在JPanel中自由绘图,并将绘图保存为jpg文件
- 将开发板的显示截图为jpg或者png
- VC屏幕截图,保存为Bmp文件
- VC屏幕截图,保存为Bmp文件
- java:截屏并保存为jpg格式
- 获取视频的每一帧,并保存为.jpg图片
- Struts2入门——3,框架配置文件
- 一张图表示三层
- 机房收费系统之添加数据
- 原型模式
- SeekBar总结
- Windows客户端开发--截图并保存为JPG文件
- android——四个常见控件的使用简介
- 进程死锁及解决办法
- Spring学习第二天:Spring_IOC&DI概述
- Selenium学习5--浏览器多窗口和TimesOut
- 使用CMD命令创建Maven项目()
- REST简介
- 至16年9月11日 学习总结
- HDU 5507 GT and strings 字符串相关暴力