Bmp文件怎么转换为JPG文件?

解决方案 »

  1.   

    试试GDI+,里面有个Image类,你要什么格式都可以转换,方便极了.
      

  2.   

    you  can  use  GDI+.  
    1.  construct  Bitmap  from  HBITMAP  
     
    2.  create  IStream  in  memory  
    WINOLEAPI  CreateStreamOnHGlobal(  
       HGLOBAL  hGlobal,  
       BOOL  fDeleteOnRelease,  
       LPSTREAM*  ppstm  
    );  
    3.  Save  the  image  to  IStream  object  as  JPG.  
    The  following  code  operates  on  files,  you  can  rewrite  it  to  realize  the  feature  you  needed.  
    #include  <Stdio.h>  
    #include  <Objbase.h>  
    #include  <Windows.h>  
    #include  <Gdiplus.h>  
    #include  <GdiPlusEnums.h>  
    using  namespace  Gdiplus;  
    #pragma  comment(lib,"gdiplus")  
    //  Helper  functions  
    int  GetCodecClsid(const  WCHAR*,  CLSID*);  
     
    int  main()  
    {  
               CLSID                            codecClsid;  
               EncoderParameters    encoderParameters;  
               long                              quality;  
               Status                          stat;  
               GdiplusStartupInput  gdiplusStartupInput;    
               ULONG  gdiplusToken;    
               GdiplusStartup(&gdiplusToken,  &gdiplusStartupInput,  NULL);    
               {  
                           //  Get  an  image  from  the  disk.  
                           Image  image(L"F:\\ddd.bmp");  
                             
                           //  Get  the  CLSID  of  the  JPEG  codec.  
                           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  =  0;  
                           encoderParameters.Parameter[0].Value  =  &quality;  
                           stat  =  image.Save(L"Shapes001.jpg",  &codecClsid,  &encoderParameters);  
                             
                           if(stat  ==  Ok)  
                                       wprintf(L"%s  saved  successfully.\n",  L"Shapes001.jpg");  
                           else  
                                       wprintf(L"%d    Attempt  to  save  %s  failed.\n",  stat,  L"Shapes001.jpg");  
                             
                           //  Save  the  image  as  a  JPEG  with  quality  level  50.  
                           quality  =  50;  
                           encoderParameters.Parameter[0].Value  =  &quality;  
                           stat  =  image.Save(L"Shapes050.jpg",  &codecClsid,  &encoderParameters);  
                             
                           if(stat  ==  Ok)  
                                       wprintf(L"%s  saved  successfully.\n",  L"Shapes050.jpg");  
                           else  
                                       wprintf(L"%d    Attempt  to  save  %s  failed.\n",  stat,  L"Shapes050.jpg");  
                             
                           //  Save  the  image  as  a  JPEG  with  quality  level  100.  
                           quality  =  100;  
                           encoderParameters.Parameter[0].Value  =  &quality;  
                           stat  =  image.Save(L"Shapes100.jpg",  &codecClsid,  &encoderParameters);  
                             
                           if(stat  ==  Ok)  
                                       wprintf(L"%s  saved  successfully.\n",  L"Shapes100.jpg");  
                           else  
                                       wprintf(L"%d    Attempt  to  save  %s  failed.\n",  stat,  L"Shapes100.jpg");  
               }  
               GdiplusShutdown(gdiplusToken);  
               return  0;  
    }  //  main  
    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(int  j  =  0;  j  <  num;  ++j)  
         {  
               if(  wcscmp(pImageCodecInfo[j].MimeType,  format)  ==  0  )  
               {  
                     *pClsid  =  pImageCodecInfo[j].Clsid;  
                     return  j;    //  Success  
               }          
         }  //  for  
     
         return  -1;    //  Failure  
     
    }  //  GetCodecClsid  
    //download  gdiplus.dll    
    //http://www.microsoft.com/downloads/release.asp?releaseid=32738  
    //Platform  SDK  Redistributable:  GDI+  RTM    
     
      

  3.   

    http://community.csdn.net/Expert/TopicView.asp?id=3345477
      

  4.   

    哈哈,还有个问题
    JPG文件怎么转换为Bmp文件?
      

  5.   

    找个CxImage,想转啥都在里面了
      

  6.   

    一群傻瓜,用photoshop不就的了
      

  7.   

    Jaogoy(想你) ( ) 信誉:100 
    谁啊,敢在这撒野!
    这不是你该来的地方
      

  8.   

    jpeg lib 支持就好了~~~~~~~
    自己编码要对图象的编码学很好才行