Does any one know a routine/ method to change an image from Bmp to a JPG?
Thanks
Printable View
Does any one know a routine/ method to change an image from Bmp to a JPG?
Thanks
You can use Image Class of GDI+.
Cheers
Or cxImage, but this might be a library too big for this task only.
You don't need anything.
Just use Win32 SHC api , which convert any graphic format
+ what SHC api?
You could use this COM dll which has a very easy to use interface to convert bitmaps to jpegs.
You need to rename imagehandler.zip to imagehandler.cab and then you can extract the contained dll.
There's the CImage class that can do this too (since at least VS2003 IIRC).
Here is the GDI+ code using the Image class to do it.
Code:#include <GdiPlus.h>
#pragma comment(lib, "gdiplus")
void foo()
{
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
Image* pImage = Image::FromFile(L"D:\\abc.bmp", true);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
pImage->Save(L"D:\\abc.jpg", &clsid);
delete pImage;
}
GdiplusShutdown(gdiplusToken);
}
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
using namespace Gdiplus;
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
}