Board logo

标题: 支持重载的控制台图显工具imaged.exe [打印本页]

作者: happy886rr    时间: 2017-2-6 22:22     标题: 支持重载的控制台图显工具imaged.exe

image大名鼎鼎,无人不晓。而imaged.exe是作为向image致敬的产品。支持你无法想象的多得多参数杂糅。专注图像多参显示,且根据你输入的参数的不同,做出不同的函数重载,输几个参数都行,不强求,非常自然。专为论坛、贴吧中喜欢制作批处理游戏的高端玩家打造。能够随意缩放图像尺寸,任意角度显示,图像裁剪...,让你的批处理游戏美轮美奂。非常严谨的错误反馈,一点小错都会报出英文说明,让严格贯穿始终。同时为了体积,使用了VS的神优化,只有10KB方便下载。
  1. IMAGED.EXE
  2. 摘要:
  3. =============================================================================
  4. CMD控制台图片显示工具,支持bmp、png、gif、jpg、jpeg、tiff、exif、ico等多种
  5. 图片显示,包括12种参数自由设定,支持图片旋转、缩小、透明显示等特效。
  6. =============================================================================
  7. 下载:[attach]10407[/attach]
  8. 用法:
  9. -----------------------------------------------------------------------------
  10. imaged [options] {arguments}...
  11. -----------------------------------------------------------------------------
  12. BASE:
  13.     [file]  [cmd_x] [cmd_y] [cmd_with] [cmd_high]
  14.             [src_x] [src_y] [src_with] [src_high]
  15.             [rot_x] [rot_y] [rot_angle]        //Draw an image
  16. OTHER:
  17.     /help   Show help information
  18.     /hide   Hide the cursor
  19.     /show   Show the cursor
  20.     /clean  [x] [y] [with] [high]              //Clear the image
  21. -----------------------------------------------------------------------------
  22. 示例:
  23. -----------------------------------------------------------------------------
  24. imaged test.png 0 0 100 100 0 0 100 100 50 50 30    //将test.png旋转30度显示
  25. -----------------------------------------------------------------------------
  26. 备注:
  27. -----------------------------------------------------------------
  28. CONSOLE IMAGE DISPLAY TOOL, COPYRIGHT@2017~2019 BY HAPPY
  29. -----------------------------------------------------------------
  30. imaged [options] {arguments}...
  31. -----------------------------------------------------------------
  32. BASE:
  33.     [file]  [cmd_x] [cmd_y] [cmd_with] [cmd_high]
  34.             [src_x] [src_y] [src_with] [src_high]
  35.             [rot_x] [rot_y] [rot_angle]        Draw an image
  36. OTHER:
  37.     /help   Show help information
  38.     /hide   Hide the cursor
  39.     /show   Show the cursor
  40.     /clean  [x] [y] [with] [high]              Clear the image
  41. -----------------------------------------------------------------
  42. 2017-02-06, VERSION 1.0"
复制代码
仅支持VS2010编译
原创代码:
  1. /*
  2. CONSOLE IMAGE DISPLAY TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0
  3. IMAGED.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 IMAGE DISPLAY TOOL, COPYRIGHT@2017~2019 BY HAPPY\n\
  15. -----------------------------------------------------------------\n\
  16. imaged [options] {arguments}...\n\
  17. -----------------------------------------------------------------\n\
  18. BASE:\n\
  19.     [file]  [cmd_x] [cmd_y] [cmd_with] [cmd_high]\n\
  20.             [src_x] [src_y] [src_with] [src_high]\n\
  21.             [rot_x] [rot_y] [rot_angle]        Draw an image\n\
  22. OTHER:\n\
  23.     /help   Show help information\n\
  24.     /hide   Hide the cursor\n\
  25.     /show   Show the cursor\n\
  26.     /clean  [x] [y] [with] [high]              Clear the image\n\
  27. -----------------------------------------------------------------\n\
  28. 2017-02-03, VERSION 1.0"
  29. /***************定义全局变量*************/
  30. //定义关键词目
  31. #define            SENSITIVE_NUM    6
  32. static const char* SENSITIVE_WORDS[]={"/HIDE", "/SHOW", "/CLEAN", "/HELP", "/H", "/?"};
  33. static       int   PRIVATIVE_PAR[11]={0};
  34. /***************功能函数群***************/
  35. //转码款字符
  36. WCHAR* L(const CHAR* str)
  37. {
  38. if(!str){return NULL;}
  39. int wLen=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, NULL, 0);
  40. WCHAR* wstr=(WCHAR*)malloc(sizeof(WCHAR)*wLen + 1);
  41. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, wLen);
  42. wstr[wLen]='\0';
  43. return wstr;
  44. }
  45. //识别关键词
  46. int itifyWORDS(const char* strARGV)
  47. {
  48. int SN;
  49. for(SN=0; SN<SENSITIVE_NUM; SN++){
  50. char *op=(char*)strARGV, *kp=(char*)SENSITIVE_WORDS[SN];
  51. while(*kp!='\0'){
  52. if( (('a'<= *op && *op<='z')?*op-32:*op) != (('a'<= *kp && *kp<='z')?*kp-32:*kp) ){break;}
  53. op++;kp++;
  54. }
  55. if( (*kp=='\0') && (*op==' '||*op=='\t'||*op=='\r'||*op=='\n'||*op=='\0') ){return SN;}
  56. }
  57. return -1;
  58. }
  59. //显示光标
  60. BOOL DispyCursor(int size,bool mode)
  61. {
  62. CONSOLE_CURSOR_INFO cinfo ={(DWORD)size, mode};
  63. return SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cinfo);
  64. }
  65. //开关解析函数
  66. void OptRE(HWND hCMD, HDC hDC, int argc, char** argv)
  67. {
  68. //计算有效参数数目
  69. int oargc=argc-1;
  70. if(oargc==0){
  71. //无参数,则抛出使用说明
  72. fputs(HELP_INFORMATION, stderr);
  73. exit(1);
  74. }
  75. //参数接收针
  76. char** oargv=argv;
  77. //识别关键词
  78. int SN=itifyWORDS(argv[1]);
  79. if(SN!=-1){
  80. //执行基本命令
  81. switch(SN)
  82. {
  83. case 0:
  84. case 1:
  85. ///HIDE||SHOW
  86. DispyCursor((DWORD)25, (SN==0)?FALSE:TRUE);
  87. break;
  88. case 2:
  89. ///CLEAN
  90. if(oargc!=5){
  91. InvalidateRect(hCMD, NULL, FALSE);
  92. }else{
  93. RECT rc={atoi(argv[2]), atoi(argv[3]), atoi(argv[2])+atoi(argv[4]), atoi(argv[3])+atoi(argv[5])};
  94. InvalidateRect(hCMD,  &rc, FALSE);
  95. }
  96. break;
  97. default:
  98. ///HELP
  99. fputs(HELP_INFORMATION, stderr);
  100. exit(0);
  101. }
  102. }else{
  103. //读取图像
  104. Image*  srcIMG=NULL;
  105. if((srcIMG=Image::FromFile(L(argv[1])))==NULL){
  106. fputs("Read the image failed", stderr);
  107. exit(1);
  108. }
  109. int anum;
  110. for(anum=0; anum<11; anum++){
  111. if(anum+2<=oargc){
  112. PRIVATIVE_PAR[anum]=atoi(argv[anum+2]);
  113. }
  114. if      ((anum==2||anum==6) && (PRIVATIVE_PAR[anum]==0)){
  115. PRIVATIVE_PAR[anum]=srcIMG->GetWidth();
  116. }else if((anum==3||anum==7) && (PRIVATIVE_PAR[anum]==0)){
  117. PRIVATIVE_PAR[anum]=srcIMG->GetHeight();
  118. }
  119. }
  120. //旋转矩阵
  121. Matrix  matri;
  122. matri.Reset();
  123. matri.RotateAt((float)PRIVATIVE_PAR[10], PointF((float)PRIVATIVE_PAR[8], (float)PRIVATIVE_PAR[9]));
  124. //创建graph
  125. Graphics graph(hDC);
  126. graph.SetTransform(&matri);
  127. //绘制图像
  128. Status s=graph.DrawImage(srcIMG,  Rect(PRIVATIVE_PAR[0],PRIVATIVE_PAR[1],PRIVATIVE_PAR[2],PRIVATIVE_PAR[3]),  PRIVATIVE_PAR[4],PRIVATIVE_PAR[5],PRIVATIVE_PAR[6],PRIVATIVE_PAR[7],  UnitPixel);
  129. if(s!=Ok){
  130. fputs("Drawing the image failed", stderr);
  131. exit(1);
  132. }
  133. }
  134. }
  135. /*************MAIN主函数入口*************/
  136. int main(int argc, char** argv)
  137. {
  138. //初始化Gdiplus
  139. ULONG_PTR gdipludToken;
  140. GdiplusStartupInput gdiplusInput;
  141. GdiplusStartup(&gdipludToken,&gdiplusInput,NULL);
  142. //获取CMD窗口句柄
  143. HWND hCMD=GetConsoleWindow();
  144. HDC  hDC =GetDC(hCMD);
  145. //解析开关
  146. OptRE(hCMD, hDC, argc, argv);
  147. //释放DC兼顾刷新
  148. ReleaseDC(hCMD, hDC);
  149. DeleteDC(hDC);
  150. //关闭Gdiplus
  151. GdiplusShutdown(gdipludToken);
  152. return 0;
  153. }
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2