Re: VC6 image conversion using GDI+
"Joseph M. Newcomer" :
<news:muvjl6prls10sut6vvoj8kn6ra89gistio@4ax.com> mar, 15
feb 2011 04:25:58 GMT
A couple questions, see below...
On 15 Feb 2011 01:41:15 GMT, "-Nivel-" <abcd@fghij.klm> wrote:
"-Nivel-" mare? la perdiz en: <news:Xns9E8CF9FB90F6abcdfghijklm@
91.208.207.54> mas o menos el lun, 14 feb 2011 00:32:38 GMT
"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 )
Just a correction here
if(fif == FIF_TIFF )
{
#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;
****
What is this value for, and why is it not assigned anywhere? It is
used, but it is 0, so why does it need to exist?
****
Yes you are right thanks to noticed it, is a FreeImage_Save parameter and
reviewing FreeImage sources is a default parameter with a value of 0. So in
this case should be deleted.
Options for that flag are
flag = BMP_DEFAULT //Save without any compression
or
flag = BMP_SAVE_RLE //Compress the bitmap using RLE when saving
so improving the example
we can call
1.
bSuccess = FreeImage_SaveU(fif, bitmap, filenameOut);
bSuccess = FreeImage_SaveU(fif, bitmap, filenameOut, BMP_DEFAULT);
or 2.
bSuccess = FreeImage_SaveU(fif, bitmap, filenameOut, BMP_SAVE_RLE);
The new version with some corrections at the end of message.
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>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
<code>
//Version 2 Removed unused variable flag,
// Added BOOL bSuccess = FALSE;
// Changed return type from void to BOOL
// Added return bSuccess
#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
BOOL TiffToBmp(const CString &filename)
{
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// try to guess the file format from the file extension
BOOL bSuccess = FALSE;
#ifdef _UNICODE
fif = FreeImage_GetFIFFromFilenameU(filename);
#else
fif = FreeImage_GetFIFFromFilename(filename));
#endif
if(fif == FIF_TIFF)
{
#ifdef _UNICODE
// see docs for more load options, use 3rd paramater to change
// the loading behaviour
FIBITMAP *bitmap = FreeImage_LoadU( fif, filename, 0 );
#else
FIBITMAP *bitmap = FreeImage_Load( fif, filename, 0 );
#endif
if (bitmap)
{
// bitmap successfully loaded!
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, BMP_SAVE_RLE);
// or bSuccess = FreeImage_SaveU(fif, bitmap, filenameOut);
// for no compresion
#else
bSuccess = FreeImage_Save(fif, bitmap, filenameOut, BMP_SAVE_RLE);
#endif
// unless an abnormal bug, we are done !
}
}
}
}
return bSuccess;
}
<code>
Nivel