Bonjour à tous,
Je parviens à l'aide de GDI+ à convertir une image BMP en JPG, PNG et TIF en ayant une image de bonne qualité mais lorsque je tente de la convertir en GIF, la qualité est assez dégradée ! Vous pouvez le voir sur cette image que j'utilise pour tester la conversion :
Image GIF. Je souhaiterais améliorer le rendu de l'image lorsqu'elle est convertit en GIF, mais comment faire ? Je bloque sur ce problème depuis plusieurs semaines.
Merci beaucoup d'avance pour votre aide !Voici mon code :
#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
int WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance, LPSTR LigneCommande, int Affichage)
{
ULONG_PTR gdiplusPtr;
GdiplusStartupInput gdiplusStart;
GdiplusStartup (&gdiplusPtr, &gdiplusStart, NULL);
Bitmap *image = new Bitmap(L"image.bmp");
CLSID pngClsid;
Status EtatImage; // http://msdn2.microsoft.com/en-us/library/ms534175.aspx
// GetEncoderClsid(L"image/jpeg", &pngClsid);
// GetEncoderClsid(L"image/png", &pngClsid);
// GetEncoderClsid(L"image/tiff", &pngClsid);
GetEncoderClsid(L"image/gif", &pngClsid); // http://msdn.microsoft.com/en-us/library/ms533843(VS.85).aspx
// EtatImage = image->Save(L"conversion.jpg",&pngClsid, NULL);
// EtatImage = image->Save(L"conversion.png",&pngClsid, NULL);
// EtatImage = image->Save(L"conversion.tif",&pngClsid, NULL);
EtatImage = image->Save(L"conversion.gif", &pngClsid, 0);
if (EtatImage == Ok)
MessageBox(NULL, "Image convertie !", "Conversion", MB_ICONINFORMATION);
else
MessageBox(NULL, "Problème de conversion !", "Conversion", MB_ICONINFORMATION);
delete image;
GdiplusShutdown(gdiplusPtr);
return TRUE;
}
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // nombre d'encodeurs
UINT size = 0; // taille en BYTE
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size); // Récupération du nombre d'encodeurs et leur taille totale.
if (size == 0)
return -1;
pImageCodecInfo = (ImageCodecInfo*) malloc(size); // allocation mémoire pour stoquer les infos sur les codecs (pas de VirtualAlloc sinon erreur avec un objet GDI+
if (pImageCodecInfo == NULL)
return -1;
GetImageEncoders(num, size, pImageCodecInfo); //Récupération des infos des codecs
for (UINT j = 0; j < num; ++j) // On cherche le codec que l'on veux dans la liste
{
if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo); // Libération mémoire
return -1;
}