[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

图片格式转换工具imgconv.exe

IMGCONV.EXE

摘要:
==========================================================
命令行图片格式转换工具,支持bmp、png、gif、jpg、jpeg、tiff、exif、ico等多种图片格式互转。
==========================================================

链接: https://pan.baidu.com/s/158gWUQQYytCUo5ULGXCROg?pwd=fp8h


用法:
-----------------------------------------------------------------------------
imgconv [input] [output]
-----------------------------------------------------------------------------

示例:
-----------------------------------------------------------------------------
imgconv test.ico test.png    //将ico图标转为透明png
-----------------------------------------------------------------------------

备注:
-----------------------------------------------------------------------------
CONSOLE PICTURE FORMAT CONVERSION TOOL, VERSION 1.0
-----------------------------------------------------------------------------
imgconv [input] [output]
-----------------------------------------------------------------------------
        Support bmp png gif jpg  jpeg tiff exif ico
-----------------------------------------------------------------------------
COPYRIGHT@2017~2019 BY HAPPY,2017-02-06"


原创代码:
  1. /*
  2. CONSOLE PICTURE FORMAT CONVERSION TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0
  3. IMGCONV.EXE
  4. */
  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include <gdiplus.h>
  8. #pragma comment(lib, "GdiPlus.lib")
  9. //使用GDI+
  10. using namespace Gdiplus;
  11. //定义帮助说明
  12. #define HELP_INFORMATION "\
  13. -----------------------------------------------------------------\n\
  14. CONSOLE PICTURE FORMAT CONVERSION TOOL, VERSION 1.0\n\
  15. -----------------------------------------------------------------\n\
  16. imgconv [input] [output]\n\
  17. -----------------------------------------------------------------\n\
  18.         Support bmp png gif jpg  jpeg tiff exif ico\n\
  19. -----------------------------------------------------------------\n\
  20. COPYRIGHT@2017~2019 BY HAPPY,2017-02-06"
  21. //转码宽字符
  22. WCHAR* L(const CHAR* str)
  23. {
  24. if(!str){return NULL;}
  25. int wLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, NULL, 0);
  26. WCHAR* wstr=(WCHAR*)malloc(sizeof(WCHAR)*wLen + 1);
  27. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, wLen);
  28. wstr[wLen]='\0';
  29. return wstr;
  30. }
  31. //获取编码器CLSID
  32. BOOL GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  33. {
  34. UINT j, n=0, s=0;
  35. ImageCodecInfo* pInfo=NULL;
  36. GetImageEncodersSize(&n, &s);
  37. if(s==0){return FALSE;}
  38. pInfo=(ImageCodecInfo*)(malloc(s));
  39. if(pInfo==NULL){return FALSE;}
  40. GetImageEncoders(n, s, pInfo);
  41. for(j=0; j<n; j++){
  42. if(wcscmp(pInfo[j].MimeType, format)==0){
  43. *pClsid=pInfo[j].Clsid;
  44. free(pInfo);
  45. return TRUE;
  46. }   
  47. }
  48. free(pInfo);
  49. return FALSE;
  50. }
  51. //主函数入口
  52. int main(int argc, char** argv)
  53. {
  54. if(argc!=3){
  55. //输入错误,则抛出使用说明
  56. fputs(HELP_INFORMATION, stderr);
  57. exit(1);
  58. }
  59. CHAR *p=argv[2], *formatSTR=NULL;
  60. while(*p!='\0'){p++;}
  61. int   l=p-argv[2];
  62. if(l<4){
  63. //扩展名过于短小
  64. fputs("The extension is too short", stderr);
  65. exit(1);
  66. }
  67. if(argv[2][l-4]=='.'){
  68. switch(argv[2][l-3]){
  69. case 'b':
  70. formatSTR="image/bmp";
  71. break;
  72. case 'p':
  73. formatSTR="image/png";
  74. break;
  75. case 'g':
  76. formatSTR="image/gif";
  77. break;
  78. case 'i':
  79. formatSTR="image/ico";
  80. break;
  81. case 'j':
  82. formatSTR="image/jpeg";
  83. break;
  84. default:
  85. //错误的图片转换格式
  86. fputs("Wrong picture conversion format", stderr);
  87. exit(1);
  88. }
  89. }else if(argv[2][l-5]=='.'){
  90. switch(argv[2][l-4]){
  91. case 'j':
  92. formatSTR="image/jpeg";
  93. break;
  94. case 't':
  95. formatSTR="image/tiff";
  96. break;
  97. case 'e':
  98. formatSTR="image/exif";
  99. break;
  100. default:
  101. //错误的图片转换格式
  102. fputs("Wrong picture conversion format", stderr);
  103. exit(1);
  104. }
  105. }else{
  106. //错误的图片转换格式
  107. fputs("Wrong picture conversion format", stderr);
  108. exit(1);
  109. }
  110. //初始化GDI+
  111. ULONG_PTR gdipludToken;
  112. GdiplusStartupInput gdiplusInput;
  113. GdiplusStartup(&gdipludToken,&gdiplusInput,NULL);
  114. //读取图像
  115. Image* srcIMG=Image::FromFile(L(argv[1]));
  116. CLSID  clsid;
  117. if(GetEncoderClsid(L(formatSTR), &clsid)){
  118. //保存位图
  119. srcIMG->Save(L(argv[2]), &clsid, NULL);
  120. }else{
  121. //无法转换图片格式
  122. fputs("Can't conversion format", stderr);
  123. exit(1);
  124. }
  125. //关闭GDI+
  126. GdiplusShutdown(gdipludToken);
  127. return 0;
  128. }
复制代码
2

评分人数

    • bbaa: 感谢分享 之前用topng技术 + 1
    • 523066680: 感谢分享PB + 12 技术 + 1

不支持最新的webp格式,希望能加入更多的支持格式

TOP

返回列表