Re: VC6 image conversion using GDI+
"Ed" : <news:6sedndWoF8nreMvQnZ2dnUVZ_gydnZ2d@giganews.com> mas o menos
el s?b, 12 feb 2011 19:54:45 GMT
I am using Visual Studio C++ 6
Can anyone help me with using GDI+ to convert a tiff to a bmp?
Or other ways to do it?
Thanks
You can try FreeImage http://freeimage.sourceforge.net/download.html
download this archive FreeImage3150Win32.zip
You got some examples inside this folder FreeImage\Examples\Generic\
but BatchLoad.cpp is the most useful for you, because it shows how to
load and save images.
A TiffToBmp function could be something like this:
<code>
#include "..\FreeImage\FreeImage.h"
#include "..\FreeImage\FreeImagePlus.h"
#ifdef _DEBUG
# pragma comment ( lib, "..\\FreeImage\\FreeImaged.lib" )
# pragma comment ( lib, "..\\FreeImage\\FreeImagePlusd.lib" )
#else
# pragma comment ( lib, "..\\FreeImage\\FreeImage.lib" )
# pragma comment ( lib, "..\\FreeImage\\FreeImagePlus.lib" )
#endif
void TiffToBmp(const CString &filename)
{
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// try to guess the file format from the file extension
#ifdef _UNICODE
fif = FreeImage_GetFIFFromFilenameU(filename);
#else
fif = FreeImage_GetFIFFromFilename(filename));
#endif
if(fif == FIF_TARGA )
{
#ifdef _UNICODE
FIBITMAP *bitmap = FreeImage_LoadU( fif, filename, 0 );
#else
FIBITMAP *bitmap = FreeImage_Load( fif, filename, 0 );
#endif
if (bitmap)
{
// bitmap successfully loaded!
int flag = 0;
CString filenameOut;
int i = filename.ReverseFind('.');
filenameOut = filename.Left ( i );
filenameOut += _T(".bmp");
// try to guess the file format from the file extension
#ifdef _UNICODE
fif = FreeImage_GetFIFFromFilenameU(filenameOut);
#else
fif = FreeImage_GetFIFFromFilename(filenameOut));
#endif
if(fif != FIF_UNKNOWN )
{
// check that the plugin has sufficient writing and export
capabilities ...
UINT bpp = FreeImage_GetBPP(bitmap);
if(FreeImage_FIFSupportsWriting(fif) &&
FreeImage_FIFSupportsExportBPP(fif, bpp))
{
// ok, we can save the file
#ifdef _UNICODE
bSuccess = FreeImage_SaveU(fif, bitmap, filenameOut, flag);
#else
bSuccess = FreeImage_Save(fif, bitmap, filenameOut, flag);
#endif
// unless an abnormal bug, we are done !
}
}
}
}
}
<code>