Different Image Conversion Techniques
Well, so many image formats are available in the world. Like BMP (Bitmap),TIFF (Tagged Image File Format ), JPG/JPEG (Joint Photographic Experts Group),GIF (Graphic Interchange Format),PNG (Portable Network Graphics) etc.
I already mentioned that, my current multimedia project gave me a lot of chance to improve my coding practice as well as to learn a lot of new things, like GDI,GDI+,Cryptographic services etc.
One of the requirement for me was to “Convert images between different formats”. Nice requirement
And I’m in bloody confident that, I can complete my work within a day. And I started my job. But…..:(
I searched MSDN and found IPicture, (Nice COM). By using that, I load the image,resized the image, cropped, etc.. Then the main requirement is in front of the curtain. “Image conversion.” and I use the IPicture::SaveAsFile(). Then only i noticed the method thoroughly. “Saves the picture’s data into a stream in the same format that it would save itself into a file. Bitmaps use the BMP file format, metafiles the WMF format, and icons the ICO format “
So again google the keyword..
Then one of my friend suggested this page..
Converting a BMP Image to a PNG Image http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx
A very simple and nice article. by using that, we can convert the images between different formats.
code from MSDN
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
INT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CLSID encoderClsid;
Status stat;
Image* image = new Image(L”Bird.bmp”);
// Get the CLSID of the PNG encoder.
GetEncoderClsid(L”image/png”, &encoderClsid);
stat = image->Save(L”Bird.png”, &encoderClsid, NULL);
if(stat == Ok)
printf(“Bird.png was saved successfully\n”);
else
printf(“Failure: stat = %d\n”, stat);
delete image;
GdiplusShutdown(gdiplusToken);
return 0;
}
For retrieving the Class Identifier for an Encoder we can use the following formats.
- image/bmp
- image/jpeg
- image/gif
- image/tiff
- image/png
So again curtain…
If you want to cross the sea, you have to step into the waves..
At first, the waves may distract you;
But gradually, you will subdue the fear within you.
For, no wave is mightier than the power of your mind.
for http://vctipsplusplus.wordpress.com/
BijU
Recent Comments