fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include "C:\libs\CxImage\ximage.h"
  4.  
  5. using namespace std;
  6.  
  7. int main(void)
  8. {
  9. int choice,r,g,b,gray,Height,Width;
  10. Height=300;
  11. Width=300;
  12. CxImage image;
  13. cout<<"Enter 1-4 for Load File: 1.JPG 2.BMP 3.GIF 4.TIF:";
  14. cin>>choice;
  15.  
  16. switch(choice)
  17. {
  18. case 1:
  19. image.Load("test.jpg", CXIMAGE_FORMAT_JPG);
  20. break;
  21.  
  22. case 2:
  23. image.Load("test.bmp", CXIMAGE_FORMAT_BMP);
  24. break;
  25.  
  26. case 3:
  27. image.Load("test.gif", CXIMAGE_FORMAT_GIF);
  28. break;
  29.  
  30. case 4:
  31. image.Load("test.tif", CXIMAGE_FORMAT_TIF);
  32. break;
  33.  
  34. default:
  35. cout<<"can't open file!";
  36. }
  37.  
  38. BYTE *imgary=image.GetBits();
  39. for(int i=0;i<Height;i++)
  40. for(int j=0;j<Width;j++)
  41. {
  42. r=imgary[(Width*i+j)*3+2];//將R pixel值取出
  43. g=imgary[(Width*i+j)*3+1];//將G pixel值取出
  44. b=imgary[(Width*i+j)*3];//將B pixel值取出
  45. gray=(int)(r*0.299+g*0.587+b*0.114);//計算出灰階值
  46. imgary[(Width*i+j)*3+2]=gray;//存回原陣列
  47. imgary[(Width*i+j)*3+1]=gray;
  48. imgary[(Width*i+j)*3]=gray;
  49. }
  50.  
  51. cout<<"Enter 5-8 for Save File: 5.JPG 6.BMP 7.GIF 8.TIF:";
  52. cin>>choice;
  53.  
  54. switch(choice)
  55. {
  56. case 5:
  57. image.Save("test2.jpg", CXIMAGE_FORMAT_JPG);
  58. break;
  59.  
  60. case 6:
  61. image.Save("test2.bmp", CXIMAGE_FORMAT_BMP);
  62. break;
  63.  
  64. case 7:
  65. image.Save("test2.gif", CXIMAGE_FORMAT_GIF);
  66. break;
  67.  
  68. case 8:
  69. image.Save("test2.tif", CXIMAGE_FORMAT_TIF);
  70. break;
  71.  
  72. default:
  73. cout<<"can't Save File!";
  74. }
  75.  
  76. return 0;
  77. }
  78.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:36: error: C:\libs\CxImage\ximage.h: No such file or directory
prog.cpp: In function ‘int main()’:
prog.cpp:12: error: ‘CxImage’ was not declared in this scope
prog.cpp:12: error: expected `;' before ‘image’
prog.cpp:19: error: ‘image’ was not declared in this scope
prog.cpp:19: error: ‘CXIMAGE_FORMAT_JPG’ was not declared in this scope
prog.cpp:23: error: ‘CXIMAGE_FORMAT_BMP’ was not declared in this scope
prog.cpp:27: error: ‘CXIMAGE_FORMAT_GIF’ was not declared in this scope
prog.cpp:31: error: ‘CXIMAGE_FORMAT_TIF’ was not declared in this scope
prog.cpp:38: error: ‘BYTE’ was not declared in this scope
prog.cpp:38: error: ‘imgary’ was not declared in this scope
prog.cpp:38: error: ‘image’ was not declared in this scope
prog.cpp:57: error: ‘CXIMAGE_FORMAT_JPG’ was not declared in this scope
prog.cpp:61: error: ‘CXIMAGE_FORMAT_BMP’ was not declared in this scope
prog.cpp:65: error: ‘CXIMAGE_FORMAT_GIF’ was not declared in this scope
prog.cpp:69: error: ‘CXIMAGE_FORMAT_TIF’ was not declared in this scope
stdout
Standard output is empty