CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

将其它格式的图形文件转换位bmp文件!

楼主lvsam(森)2003-08-01 17:59:12 在 VC/MFC / 基础类 提问

如何将其它格式的图形文件(jpeg,gif的主要的就行)转换位bmp文件,又没有现成的dll库之类,或者控件? 问题点数:0、回复次数:6Top

1 楼masterz(www.fruitfruit.com)回复于 2003-08-01 18:38:14 得分 0

#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*);  
  HRESULT   __fastcall   AnsiToUnicode(LPCSTR   pszA,   LPOLESTR*   ppszW)  
  {  
          ULONG   cCharacters;  
          DWORD   dwError;  
          if   (NULL   ==   pszA)  
          {  
                  *ppszW   =   NULL;  
                  return   NOERROR;  
          }  
          cCharacters   =     strlen(pszA)+1;  
          *ppszW   =   (LPOLESTR)   CoTaskMemAlloc(cCharacters*2);  
          if   (NULL   ==   *ppszW)  
                  return   E_OUTOFMEMORY;  
          if   (0   ==   MultiByteToWideChar(CP_ACP,   0,   pszA,   cCharacters,*ppszW,   cCharacters))  
          {  
                  dwError   =   GetLastError();  
                  CoTaskMemFree(*ppszW);  
                  *ppszW   =   NULL;  
                  return   HRESULT_FROM_WIN32(dwError);  
          }  
   
          return   NOERROR;  
  }  
   
   
  int   main(int   argc,   char*   argv[])  
  {  
  int   n_ret=0;  
  printf("%s   can   convert   jpg,   png,   gif,   tiff   to   bmp   file.\n   if   it   works,   it   is   written   by   masterz,   otherwise   I   don't   know   who   write   it",argv[0]);  
  if(argc!=3)  
  {  
  printf("usage:%s   bmp_filename   source_image_filename\n",argv[0]);  
  return   -1;  
  }  
  GdiplusStartupInput   gdiplusStartupInput;    
  ULONG   gdiplusToken;    
  GdiplusStartup(&gdiplusToken,   &gdiplusStartupInput,   NULL);    
  {  
  CLSID                             codecClsid;  
  Status                           stat;  
  EncoderParameters     encoderParameters;  
   
  GetCodecClsid(L"image/bmp",   &codecClsid);  
  encoderParameters.Count   =   0;  
  LPOLESTR   bstr_src_img;  
  LPOLESTR   bstr_dst_bmp;  
  AnsiToUnicode(argv[1],&bstr_dst_bmp);  
  AnsiToUnicode(argv[2],&bstr_src_img);  
  Image   image(bstr_src_img);  
  stat   =image.Save(bstr_dst_bmp,   &codecClsid,   &encoderParameters);  
  if(stat   ==   Ok)  
  {  
  n_ret=0;  
  wprintf(L"%s   saved   successfully.\n",bstr_dst_bmp);  
  }  
  else  
  {  
  n_ret=-2;  
  wprintf(L"%d     Attempt   to   save   %s   failed.\n",   stat,   bstr_dst_bmp);  
  }  
  CoTaskMemFree(bstr_dst_bmp);  
  CoTaskMemFree(bstr_src_img);  
  }  
  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(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  
  //in   order   to   compile   this   program,   you   need   to   download   microsoft   platform   sdk   from   http://www.microsoft.com/msdownload/platformsdk/sdkupdate/downlevel.htm  
  //also   download   gdiplus.dll   and   put   it   at   the   same   directory   as   the   executable.  
  //http://www.microsoft.com/downloads/release.asp?releaseid=32738  
  //Platform   SDK   Redistributable:   GDI+   RTM    
   
  //sample   usage:   img2bmp   a.bmp   b.gif  
  Top

2 楼ahu9870(阿胡9870)回复于 2003-08-01 18:41:01 得分 0

显然有,  
  搜索一下。Top

3 楼cbz(cbz)回复于 2003-08-01 18:42:04 得分 0

如果是C++Builder的话,那倒是很方便了,vc+,看看各位的高见Top

4 楼lvsam(&#26862;)回复于 2003-08-04 10:02:57 得分 0

To   masterz(MS   MVP):  
  程序中的Gdiplus.h从那里得到呀?谢谢!!Top

5 楼houdy(致力于图像/图形领域,成为有思想的程序员)回复于 2003-08-04 12:11:52 得分 0

你可以使用GDI++,VC   7.0(也就是VS.Stdio)提供的。图像处理,图像转换的基本操作里面都包括了。  
  你也可是使用别人做好的类库。比如CxImage,FreeImage等。网上有很多的。  
  还有就是自己写(如果你够牛的话)。Top

6 楼DeautyFan(可可魔仙)回复于 2003-08-04 12:44:03 得分 0

搜索一下Top

相关问题

  • 图形格式转换
  • 关注:怎样才能将JPG(JPEG)格式的图形文件转换成BMP格式的图形文件呢???
  • 关于BMP图形格式
  • 图形高手:请问如何将Bmp或Jpeg文件转换成3dHome的格式文件,有大批量的图需要转换?
  • *.bmp怎样转换为*.ico格式?
  • BMP转换成 emf或 wmf格式????????????
  • 请教png图片格式转换bmp。
  • jpeg和bmp格式的相互转换
  • 求bmp文件格式转换方法
  • 将BMP转换成JPEG格式。

关键词

  • 文件
  • null
  • ppszw
  • ccharacters
  • bmp
  • psza
  • pimagecodecinfo
  • codecclsid
  • getcodecclsid
  • bstr

得分解答快速导航

  • 帖主:lvsam

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo