Advertisement
seba101

asdasdasd

Apr 14th, 2019
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. #include "pch.h"
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <windows.h>
  6. #include <gdiplus.h>
  7.  
  8. #pragma comment( lib, "gdiplus.lib" )
  9.  
  10. using namespace Gdiplus;
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16. EncoderParameters encoderParameters;
  17. encoderParameters.Count = 1;
  18. encoderParameters.Parameter[0].Guid = EncoderQuality;
  19. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  20. encoderParameters.Parameter[0].NumberOfValues = 1;
  21.  
  22.  
  23. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
  24. GdiplusStartupInput gdiplusStartupInput;
  25. ULONG_PTR gdiplusToken;
  26. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  27.  
  28. CLSID encoderClsid;
  29. Status stat;
  30. Image* image;
  31.  
  32.  
  33. // KOLOROWY DO PNG JPG GID BMP //
  34. image = new Image(L"lena512color.tiff");
  35.  
  36. GetEncoderClsid(L"image/png", &encoderClsid);
  37. stat = image->Save(L"kompresjakolor/lena.png", &encoderClsid, NULL);
  38.  
  39. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  40. ULONG quality = 100;
  41. encoderParameters.Parameter[0].Value = &quality;
  42. stat = image->Save(L"kompresjakolor/lena.jpg", &encoderClsid, &encoderParameters);
  43.  
  44. GetEncoderClsid(L"image/GIF", &encoderClsid);
  45. stat = image->Save(L"kompresjakolor/lena.gif", &encoderClsid, NULL);
  46.  
  47. GetEncoderClsid(L"image/bmp", &encoderClsid);
  48. stat = image->Save(L"kompresjakolor/lena.bmp", &encoderClsid, NULL);
  49. // KONIEC //
  50.  
  51. // CZARNO BIALY DO PNG JPG GIF TIFF //
  52. image = new Image(L"lena512.bmp");
  53.  
  54. GetEncoderClsid(L"image/png", &encoderClsid);
  55. stat = image->Save(L"kompresjaczarnobiala/lena.png", &encoderClsid, NULL);
  56.  
  57. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  58. quality = 100;
  59. encoderParameters.Parameter[0].Value = &quality;
  60. stat = image->Save(L"kompresjaczarnobiala/lena.jpg", &encoderClsid, &encoderParameters);
  61.  
  62. GetEncoderClsid(L"image/GIF", &encoderClsid);
  63. stat = image->Save(L"kompresjaczarnobiala/lena.gif", &encoderClsid, NULL);
  64.  
  65. GetEncoderClsid(L"image/tiff", &encoderClsid);
  66. stat = image->Save(L"kompresjaczarnobiala/lena.tiff", &encoderClsid, NULL);
  67. //KONIEC//
  68.  
  69. // CZARNO BIALY JPG 5,25,50,100 //
  70.  
  71. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  72. quality = 5;
  73. encoderParameters.Parameter[0].Value = &quality;
  74. stat = image->Save(L"kompresjajpg/lena5.jpg", &encoderClsid, &encoderParameters);
  75.  
  76. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  77. quality = 25;
  78. encoderParameters.Parameter[0].Value = &quality;
  79. stat = image->Save(L"kompresjajpg/lena25.jpg", &encoderClsid, &encoderParameters);
  80.  
  81. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  82. quality = 50;
  83. encoderParameters.Parameter[0].Value = &quality;
  84. stat = image->Save(L"kompresjajpg/lena50.jpg", &encoderClsid, &encoderParameters);
  85.  
  86. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  87. quality = 100;
  88. encoderParameters.Parameter[0].Value = &quality;
  89. stat = image->Save(L"kompresjajpg/lena100.jpg", &encoderClsid, &encoderParameters);
  90.  
  91. // KONIEC//
  92.  
  93.  
  94. // KOMPRESJA TIFF //
  95.  
  96. encoderParameters.Count = 1;
  97. encoderParameters.Parameter[0].Guid = EncoderCompression;
  98. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  99. encoderParameters.Parameter[0].NumberOfValues = 1;
  100.  
  101.  
  102. quality = 2;
  103. encoderParameters.Parameter[0].Value = &quality;
  104. GetEncoderClsid(L"image/tiff", &encoderClsid);
  105. stat = image->Save(L"kompresjatiff/lenaLZW.tiff", &encoderClsid, &encoderParameters);
  106.  
  107. quality = 3;
  108. encoderParameters.Parameter[0].Value = &quality;
  109. GetEncoderClsid(L"image/tiff", &encoderClsid);
  110. stat = image->Save(L"kompresjatiff/lenaCCITT3.tiff", &encoderClsid, &encoderParameters);
  111.  
  112. quality = 4;
  113. encoderParameters.Parameter[0].Value = &quality;
  114. GetEncoderClsid(L"image/tiff", &encoderClsid);
  115. stat = image->Save(L"kompresjatiff/lenaCCITT4.tiff", &encoderClsid, &encoderParameters);
  116.  
  117. quality = 5;
  118. encoderParameters.Parameter[0].Value = &quality;
  119. GetEncoderClsid(L"image/tiff", &encoderClsid);
  120. stat = image->Save(L"kompresjatiff/lenaRle.tiff", &encoderClsid, &encoderParameters);
  121.  
  122. quality = 6;
  123. encoderParameters.Parameter[0].Value = &quality;
  124. GetEncoderClsid(L"image/tiff", &encoderClsid);
  125. stat = image->Save(L"kompresjatiff/lenaNone.tiff", &encoderClsid, &encoderParameters);
  126.  
  127. //KONIEC//
  128.  
  129.  
  130. if (stat == Ok)
  131. printf("Bird.png was saved successfully\n");
  132. else
  133. printf("Failure: stat = %d\n", stat);
  134.  
  135. delete image;
  136. GdiplusShutdown(gdiplusToken);
  137. _getch();
  138. }
  139.  
  140. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) {
  141. UINT num = 0;
  142. UINT size = 0;
  143.  
  144. GetImageEncodersSize(&num, &size);
  145. if (size == 0)
  146. return -1;
  147.  
  148. ImageCodecInfo* pICI = new ImageCodecInfo[size];
  149. if (!pICI)
  150. return -1;
  151.  
  152. GetImageEncoders(num, size, pICI);
  153.  
  154. for (UINT j = 0; j < num; ++j)
  155. if (wcscmp(pICI[j].MimeType, format) == 0) {
  156. *pClsid = pICI[j].Clsid;
  157.  
  158. delete[] pICI;
  159. return j;
  160. }
  161.  
  162.  
  163. delete[] pICI;
  164. return -1;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement