使用GDI+转换图片格式
来源:互联网 发布:免费梆定域名 编辑:程序博客网 时间:2024/05/11 13:34
调用ImageConvert函数即可,测试代码在http://download.csdn.net/detail/qq1134993111/6227899
ImageConverter.h
/* 转换图片格式 GDI+支持的格式*/#pragma once#include <wtypes.h>#include <guiddef.h>#include <string>using namespace std;#include <GdiPlus.h>using namespace Gdiplus;#pragma comment(lib,"gdiplus")//获取format对应类型的图片解码器的CLSIDint GetEncoderClsid(const WCHAR* format, CLSID* pClsid);/* wstrImageSrcPath 源图片文件全路径(包括扩展名) wstrImageDesPath 转换后文件存放全路径(包括括展名)wstrFormatType 转换参数,例如:L"image/png" 、L"image/bmp" 等等。要和wstrImageDesPath路径中的图像格式一样返回值为true表示成功*/bool ImageConvert(wstring wstrImageSrcPath,wstring wstrImageDesPath,wstring wstrFormatType);
ImageConverter.cpp
#include "ImageConverter.h"int GetEncoderClsid(const WCHAR* format, CLSID* pClsid){UINT num = 0; // number of image encodersUINT size = 0; // size of the image encoder array in bytesImageCodecInfo* pImageCodecInfo = NULL;//2.获取GDI+支持的图像格式编码器种类数以及ImageCodecInfo数组的存放大小GetImageEncodersSize(&num, &size);if(size == 0)return -1; // Failure//3.为ImageCodecInfo数组分配足额空间pImageCodecInfo = (ImageCodecInfo*)(malloc(size));if(pImageCodecInfo == NULL)return -1; // Failure//4.获取所有的图像编码器信息GetImageEncoders(num, size, pImageCodecInfo);//5.查找符合的图像编码器的Clsidfor(UINT j = 0; j < num; ++j){if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ){*pClsid = pImageCodecInfo[j].Clsid;free(pImageCodecInfo);return j; // Success} }//6.释放步骤3分配的内存free(pImageCodecInfo);return -1; // Failure}bool ImageConvert(wstring wstrImageSrcPath,wstring wstrImageDesPath,wstring wstrFormatType){GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;//1.初始化GDI+,以便后续的GDI+函数可以成功调用GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);CLSID encoderClsid;Status stat;//7.创建Image对象并加载图片Image* image = new Image(wstrImageSrcPath.c_str());// Get the CLSID of the wstrFormatType Corresponding picture type encoder. 获取wstrFormatType对应类型的图片解码器的CLSIDGetEncoderClsid(wstrFormatType.c_str(), &encoderClsid);//8.调用Image.Save方法进行图片格式转换,并把步骤3)得到的图像编码器Clsid传递给它stat = image->Save(wstrImageDesPath.c_str(), &encoderClsid, NULL); bool bRet;if(stat == Ok)bRet=true;else bRet=false;//9.释放Image对象delete image;//10.清理所有GDI+资源GdiplusShutdown(gdiplusToken);return bRet;}
- 使用GDI+转换图片格式
- windows 使用GDI+来转换图片格式
- 在VC6中使用GDI的方法(附一个使用GDI+的批量图片格式转换程序)
- 使用cygwin转换图片格式
- 利用GDI+实现常见图片格式任意转换的函数
- 利用GDI+图片格式转换(例如BMP转PNG)
- 利用GDI+图片格式转换(例如BMP转PNG)
- GDI+实现图片格式转换(bmp、jpeg、gif、tiff、png) .
- GDI+实现图片格式转换(bmp、jpeg、gif、tiff、png)
- GDI+实现图片格式转换(bmp、jpeg、gif、tiff、png)
- 使用python进行图片格式转换
- 创建支持更多图片格式的按钮 使用VC6和GDI+
- 使用GDI+创建支持更多图片格式的按钮
- 转换图片格式
- 转换图片格式
- 图片格式转换
- 图片格式转换
- 图片格式转换
- Jquery 事件冒泡
- 手工创建Oracle数据库
- 霍夫变换
- python challenge level1
- Python快速教程
- 使用GDI+转换图片格式
- 一位数据挖掘成功人士给数据挖掘在读研究生的建议
- HDU 2296 Ring (AC自动机+DP,5级)
- eclipse快捷键
- OpenCV 2.4.X最常用的数据类型
- 程序员面试智力题(一)
- 交换两变量 只用两个表达式
- 析构函数 虚函数
- 文件的输入和输出-cin用法