我想把bmp压缩转换成jpg格式的,谢谢大家

解决方案 »

  1.   

    在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
      

  2.   

    声明:事先还需要配置好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
      

  3.   

    楼主可以参考我在下面贴子里的回答,也许对你有帮助http://community.csdn.net/Expert/topic/4411/4411860.xml?temp=.9722406
      

  4.   

    http://www.vckbase.com/code/listcode.asp?mclsid=7&sclsid=703一个源代码,呵呵