bmp转jpg 我想把bmp压缩转换成jpg格式的,谢谢大家 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在C**App类的h文件中添加如下://////////////////////////////////////////必要的宏 以及头文件#define UNICODE#ifndef ULONG_PTR#define ULONG_PTR unsigned long*#endif#include <gdiplus.h> using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") //link gdiplus.lib//////////////////////////////////////// 然后在C**App类中添加如下成员变量!(不可作为全局变量,否则link时出错,重复定义) GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken;然后到InitInstance中: GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);到ExitInstance中: Gdiplus::GdiplusShutdown(m_gdiplusToken); 然后即可:Image Im(L"c:\\fig.bmp", FALSE);CLSID JpgCodec;GetCodecClsid(L"image/jpg", &JpgCodec);Im.Save(L"c:\\fig.jpg", &JpgCodec, NULL);Here is the code to GetCodecClsid int GetCodecClsid(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; return j; // Success } } // for return -1; // Failure} // GetCodecClsid 声明:事先还需要配置好GdiPlus的环境方法如下:1 到http://www.bypro.net/PostAttachment.aspx?PostID=21280&AttachmentID=1787下载GdiPlus开发包,释放到VC的相应Include、lib文件夹中,把dll放到windows文件夹中2 到VC的Tools-Directories中分别添加一项Include和lib,指向你刚才释放的文件夹。比如我添加一项IncludeFiles为:C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\INCLUDE\GDIPLUS添加一项LibraryFiles为:C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\LIB\GDIPLUS 楼主可以参考我在下面贴子里的回答,也许对你有帮助http://community.csdn.net/Expert/topic/4411/4411860.xml?temp=.9722406 http://www.vckbase.com/code/listcode.asp?mclsid=7&sclsid=703一个源代码,呵呵 静态分裂视图 CFormView视图控件如何获取其句柄 有关TTF字体文件的详细结构的问题 基于原始套接字的端口扫描器 vc++ 我晕呀 如何在vc中实现office中那种从视图右下角动态弹出、隐藏的对话框? 我是新手,清高首赐教:在对话框窗口中,有一个文本框,一个按钮,如何利用按钮更新文本框? vc错误Access Violation 关于控制刻录机(CD_WR)? List Box的消息响应问题 我要学VC! long型数据存在的意义是什么? 子窗口(或控件)如何实现拖到边缘,改变大小之类的
//必要的宏 以及头文件
#define UNICODE
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib") //link gdiplus.lib////////////////////////////////////////
然后在C**App类中添加如下成员变量!
(不可作为全局变量,否则link时出错,重复定义)
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;然后到InitInstance中:
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
到ExitInstance中:
Gdiplus::GdiplusShutdown(m_gdiplusToken); 然后即可:
Image Im(L"c:\\fig.bmp", FALSE);
CLSID JpgCodec;
GetCodecClsid(L"image/jpg", &JpgCodec);
Im.Save(L"c:\\fig.jpg", &JpgCodec, NULL);
Here is the code to GetCodecClsid int GetCodecClsid(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;
return j; // Success
}
} // for return -1; // Failure
} // GetCodecClsid
方法如下:
1 到
http://www.bypro.net/PostAttachment.aspx?PostID=21280&AttachmentID=1787
下载GdiPlus开发包,释放到VC的相应Include、lib文件夹中,把dll放到windows文件夹中2 到VC的Tools-Directories中分别添加一项Include和lib,指向你刚才释放的文件夹。
比如我添加一项IncludeFiles为:C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\INCLUDE\GDIPLUS
添加一项LibraryFiles为:C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\LIB\GDIPLUS