Click here to Skip to main content
15,917,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to Convert a BMP Image to a JPEG ... Pin
tns_ranjith15-Oct-08 2:03
tns_ranjith15-Oct-08 2:03 
JokeRe: How to Convert a BMP Image to a JPEG ... Pin
CPallini15-Oct-08 5:29
mveCPallini15-Oct-08 5:29 
AnswerRe: How to Convert a BMP Image to a JPEG ... Pin
James R. Twine15-Oct-08 1:40
James R. Twine15-Oct-08 1:40 
AnswerRe: How to Convert a BMP Image to a JPEG ... Pin
Mark Salsbery15-Oct-08 6:12
Mark Salsbery15-Oct-08 6:12 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
aa_zz26-Oct-08 21:16
aa_zz26-Oct-08 21:16 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
Mark Salsbery27-Oct-08 4:38
Mark Salsbery27-Oct-08 4:38 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
aa_zz28-Oct-08 16:23
aa_zz28-Oct-08 16:23 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
Mark Salsbery28-Oct-08 16:36
Mark Salsbery28-Oct-08 16:36 
CImage is a class shared by ATL and MFC these days.

It uses GDI+ for image loading and saving.
Here's the GDI+ version:
#include <gdiplus.h>


// This function stolen from the GDI+ docs

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
}


...

// Convert a JPEG to a BMP with GDI+

	ULONG dwToken;
	Gdiplus::GdiplusStartupInput input;
	Gdiplus::GdiplusStartupOutput output;
	Gdiplus::Status status = Gdiplus::GdiplusStartup(&dwToken, &input, &output);
	if(status == Gdiplus::Ok)
	{
		Gdiplus::Bitmap *pSrcBitmap = new Gdiplus::Bitmap(L"c:\\test.jpg", FALSE);
		CLSID bmpClsid;
		GetEncoderClsid(L"image/bmp", &bmpClsid);
		pSrcBitmap->Save(L"c:\\test.bmp", &bmpClsid);
		delete pSrcBitmap;

		Gdiplus::GdiplusShutdown(dwToken);
	}


Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
aa_zz28-Oct-08 17:19
aa_zz28-Oct-08 17:19 
AnswerRe: How to Convert a BMP Image to a JPEG ... Pin
Hamid_RT15-Oct-08 21:44
Hamid_RT15-Oct-08 21:44 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
reddy7815-Oct-08 23:41
reddy7815-Oct-08 23:41 
GeneralRe: How to Convert a BMP Image to a JPEG ... Pin
Hamid_RT16-Oct-08 4:10
Hamid_RT16-Oct-08 4:10 
QuestionChanging Local Security Policy Pin
ekpravasi15-Oct-08 1:01
ekpravasi15-Oct-08 1:01 
QuestionHow to find 3rd coordinate of a triangle given 2 others Pin
Chesnokov Yuriy15-Oct-08 1:00
professionalChesnokov Yuriy15-Oct-08 1:00 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini15-Oct-08 2:32
mveCPallini15-Oct-08 2:32 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Rajesh R Subramanian15-Oct-08 2:43
professionalRajesh R Subramanian15-Oct-08 2:43 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini15-Oct-08 3:14
mveCPallini15-Oct-08 3:14 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini16-Oct-08 2:25
mveCPallini16-Oct-08 2:25 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Rajesh R Subramanian16-Oct-08 2:35
professionalRajesh R Subramanian16-Oct-08 2:35 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini16-Oct-08 2:50
mveCPallini16-Oct-08 2:50 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
Rajesh R Subramanian16-Oct-08 2:53
professionalRajesh R Subramanian16-Oct-08 2:53 
QuestionRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini16-Oct-08 2:57
mveCPallini16-Oct-08 2:57 
AnswerRe: How to find 3rd coordinate of a triangle given 2 others Pin
Rajesh R Subramanian16-Oct-08 3:02
professionalRajesh R Subramanian16-Oct-08 3:02 
GeneralRe: How to find 3rd coordinate of a triangle given 2 others Pin
CPallini16-Oct-08 3:16
mveCPallini16-Oct-08 3:16 
QuestionRe: How to find 3rd coordinate of a triangle given 2 others Pin
David Crow15-Oct-08 3:00
David Crow15-Oct-08 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.