小弟想把bmp图片转换成jpg文件,因为bmp文件比较大,我想通过转换成jpg文件来压缩一下图片,听说用Cimage类就可以了,可是我怎么找不到Cimage类,要引用哪个头文件呀,这个类是VC自带的吗?还是它是第三方控件类?

解决方案 »

  1.   

    我试了,好像系统并没有这歌头文件啊 ,我都是用网上的一个动态链接库来做的 好像是imageload。h  .lib  你只要加载图片,然后指定文件格式保存就行了
      

  2.   

    使用gdiplus,我blog里面有转jpg的例子
      

  3.   

    VS下有CImage类。
    很简单...
      

  4.   

    atlimage.h在vs2005中有,vc6.0中是没有的
      

  5.   

    我在VS2005里引入头文件:#include <atlimage.h>后代码如下
         CImage img; 
        img.Load(L"D:\\VC2005program\\BmpToJpg\\abc.bmp"); 
        img.Save(L"D:\\VC2005program\\BmpToJpg\\abc.jpg",ImageFormatJPEG);
    可是提示错误信息呀:错误 1 error C2065: “ImageFormatJPEG”: 未声明的标识符 d:\VC2005program\BmpToJpg\BmpToJpgDlg.cpp 160
      

  6.   

    #include <atlimage.h>
    using namespace Gdiplus ;
    #include <gdiplusimaging.h>
    =====
    按照上面的做法试试
      

  7.   

    VC6如下作:
    =========================================================
    //=======================================================================
    // 函数原型: BOOL CSYSGlobal::BMP2JPEG(LPCTSTR lpszBMPFileName, LPCTSTR lpszJPEGFileName , long lQuality /*= 100*/ )
    // 功能描述: BMP文件转换成JPEG文件  
    // 参数说明:    名称             类型                说明
    //              lpszBMPFileName  LPCTSTR             要转换的BMP文件名( 已存在文件 )
    //              lpszJPEGFileName LPCTSTR             JPEG文件名( 根据BMP转换 新生成文件 )
    //              lQuality         long                图片质量 ( 默认100% )
    // 返 回 值: 
    // 依 赖 于: GDI+, ATL字符转换( 用 A2W() 转换ASCII -> Unicode )
    //          具体 做法如下: 
    //          1. 加入GDI+支持: 在StdAfx.h的 "#endif // _AFX_NO_AFXCMN_SUPPORT" 前加入如下代码:
    //          #include <gdiplus.h>
    //          #include   <GdiPlusEnums.h> 
    //          using   namespace   Gdiplus;  
    //          #pragma comment( lib, "gdiplus.lib" )
    //          
    //          //加入ATL字符转换支持: 在StdAfx.h中加入
    //          #include <atlconv.h>
    //-----------------------------------------------------------------------
    // 引 用 表: 无
    // 更 新 表: 无 
    // 被引用于: 全局
    // 创建日期: 2007年12月21日 16时02分57秒
    // 修改日期:
    // 修改说明:    
    //=======================================================================
    BOOL CSYSGlobal::BMP2JPEG(LPCTSTR lpszBMPFileName, LPCTSTR lpszJPEGFileName, long lQuality /*= 100*/ )
    {
        USES_CONVERSION; //调用  A2W() 等宏时,必须先执行该行!!!
        
        CLSID               codecClsid;   
        EncoderParameters   encoderParameters;   
        long                quality;   
        Status              stat;   
        GdiplusStartupInput gdiplusStartupInput;     
        ULONG               gdiplusToken;  
        BOOL                bRet = TRUE;
        
        WCHAR wszcBmpFileName[ 512 ];
        WCHAR wszJpgFileName[ 512 ];
        WCHAR *lpwcBmpFileName = NULL;
        WCHAR *lpwcJpgFileName = NULL;#ifdef UNICODE
        wcscpy( wszcBmpFileName, lpszBMPFileName );
        wcscpy( wszJpgFileName, lpszJPEGFileName );
    #else
        lpwcBmpFileName = A2W( lpszBMPFileName );
        lpwcJpgFileName = A2W( lpszJPEGFileName );
        wcscpy( wszcBmpFileName, lpwcBmpFileName );
        wcscpy( wszJpgFileName, lpwcJpgFileName );
    #endif
        GdiplusStartup(&gdiplusToken,   &gdiplusStartupInput,   NULL);     
        {   
            // Get an image from the disk.   
            Image   image( wszcBmpFileName );           // Get the CLSID of the JPEG codec.   
            CSYSGlobal::GetCodecClsid( L"image/jpeg",   &codecClsid );           //   Before we call Image::Save, we must initialize an   
            //   EncoderParameters object. The EncoderParameters object   
            //   has an array of EncoderParameter objects. In this   
            //   case, there is only one EncoderParameter object in the array.   
            //   The one EncoderParameter object has an array of values.   
            //   In this case, there is only one value ( of type LONG )   
            //   in the array. We will set this value to 0, 50, and 100.           encoderParameters.Count   =   1;   
            encoderParameters.Parameter[0].Guid   =   EncoderQuality;   
            encoderParameters.Parameter[0].Type   =   EncoderParameterValueTypeLong;   
            encoderParameters.Parameter[0].NumberOfValues   =   1;           // Save   the   image   as   a   JPEG   with   quality   level   0.   
            quality = lQuality;   
            encoderParameters.Parameter[0].Value   =   &quality;   
            stat = image.Save( wszJpgFileName,   &codecClsid,   &encoderParameters);           if( stat == Ok )  
            {
                //AfxMessageBox( _T( "保存JPEG文件成功" ) );
                bRet = TRUE;
            }
            else   
            {
                AfxMessageBox( _T( "保存JPEG文件失败!" ) );
                bRet = FALSE;
            }
        }       GdiplusShutdown(gdiplusToken); 
        
        return bRet;
    }//=======================================================================
    // 函数原型: int CSYSGlobal::GetCodecClsid(const WCHAR *format, CLSID *pClsid)
    // 功能描述:   
    // 参数说明:    名称            类型                说明
    // 返 回 值: 
    // 依 赖 于: 无
    // 引 用 表: 无
    // 更 新 表: 无 
    // 被引用于: BOOL CSYSGlobal::BMP2JPEG(LPCTSTR lpszBMPFileName, LPCTSTR lpszJPEGFileName )
    // 创建日期: 2007年12月21日 16时43分28秒
    // 修改日期:
    // 修改说明:    
    //=======================================================================
    int CSYSGlobal::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( int j = 0; j < num; ++j )   
        {   
            if( wcscmp(pImageCodecInfo[j].MimeType, format ) == 0 )   
            {   
                *pClsid   =   pImageCodecInfo[j].Clsid;   
                return   j;     //   Success   
            }           
        }   //   for       return   -1;     //   Failure   
    }
      

  8.   

    上面那个放到EVC里可以用吗?