Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <conio.h>
- #include <stdio.h>
- #include <iostream>
- #include <windows.h>
- #include <gdiplus.h>
- #pragma comment( lib, "gdiplus.lib" )
- using namespace Gdiplus;
- int main()
- {
- EncoderParameters encoderParameters;
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderQuality;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
- int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- CLSID encoderClsid;
- Status stat;
- Image* image;
- // KOLOROWY DO PNG JPG GID BMP //
- image = new Image(L"lena512color.tiff");
- GetEncoderClsid(L"image/png", &encoderClsid);
- stat = image->Save(L"kompresjakolor/lena.png", &encoderClsid, NULL);
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- ULONG quality = 100;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjakolor/lena.jpg", &encoderClsid, &encoderParameters);
- GetEncoderClsid(L"image/GIF", &encoderClsid);
- stat = image->Save(L"kompresjakolor/lena.gif", &encoderClsid, NULL);
- GetEncoderClsid(L"image/bmp", &encoderClsid);
- stat = image->Save(L"kompresjakolor/lena.bmp", &encoderClsid, NULL);
- // KONIEC //
- // CZARNO BIALY DO PNG JPG GIF TIFF //
- image = new Image(L"lena512.bmp");
- GetEncoderClsid(L"image/png", &encoderClsid);
- stat = image->Save(L"kompresjaczarnobiala/lena.png", &encoderClsid, NULL);
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- quality = 100;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjaczarnobiala/lena.jpg", &encoderClsid, &encoderParameters);
- GetEncoderClsid(L"image/GIF", &encoderClsid);
- stat = image->Save(L"kompresjaczarnobiala/lena.gif", &encoderClsid, NULL);
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjaczarnobiala/lena.tiff", &encoderClsid, NULL);
- //KONIEC//
- // CZARNO BIALY JPG 5,25,50,100 //
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- quality = 5;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjajpg/lena5.jpg", &encoderClsid, &encoderParameters);
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- quality = 25;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjajpg/lena25.jpg", &encoderClsid, &encoderParameters);
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- quality = 50;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjajpg/lena50.jpg", &encoderClsid, &encoderParameters);
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- quality = 100;
- encoderParameters.Parameter[0].Value = &quality;
- stat = image->Save(L"kompresjajpg/lena100.jpg", &encoderClsid, &encoderParameters);
- // KONIEC//
- // KOMPRESJA TIFF //
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderCompression;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
- quality = 2;
- encoderParameters.Parameter[0].Value = &quality;
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjatiff/lenaLZW.tiff", &encoderClsid, &encoderParameters);
- quality = 3;
- encoderParameters.Parameter[0].Value = &quality;
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjatiff/lenaCCITT3.tiff", &encoderClsid, &encoderParameters);
- quality = 4;
- encoderParameters.Parameter[0].Value = &quality;
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjatiff/lenaCCITT4.tiff", &encoderClsid, &encoderParameters);
- quality = 5;
- encoderParameters.Parameter[0].Value = &quality;
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjatiff/lenaRle.tiff", &encoderClsid, &encoderParameters);
- quality = 6;
- encoderParameters.Parameter[0].Value = &quality;
- GetEncoderClsid(L"image/tiff", &encoderClsid);
- stat = image->Save(L"kompresjatiff/lenaNone.tiff", &encoderClsid, &encoderParameters);
- //KONIEC//
- if (stat == Ok)
- printf("Bird.png was saved successfully\n");
- else
- printf("Failure: stat = %d\n", stat);
- delete image;
- GdiplusShutdown(gdiplusToken);
- _getch();
- }
- int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) {
- UINT num = 0;
- UINT size = 0;
- GetImageEncodersSize(&num, &size);
- if (size == 0)
- return -1;
- ImageCodecInfo* pICI = new ImageCodecInfo[size];
- if (!pICI)
- return -1;
- GetImageEncoders(num, size, pICI);
- for (UINT j = 0; j < num; ++j)
- if (wcscmp(pICI[j].MimeType, format) == 0) {
- *pClsid = pICI[j].Clsid;
- delete[] pICI;
- return j;
- }
- delete[] pICI;
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement