1.11M Members

How to convert screenshot(bmp) to jpeg?

 
0
 

I have some code I found that takes screenshots and saves them as a bitmap image. I'm trying to get it to save the screenshots as .jpg and I don't know how to. I don't want to use a large third party library if I don't have to, I would prefer something small and specialised. Any ideas? I would prefer the screenshot not be written to file then converted, but rather be converted "in ram".

Code at:http://pastebin.com/XB6U2yDY

 
0
 

Thank you very much. Also, if I were to use one of those libs which variable(s) would I want to plug into a function?
Edit: It seems ImageMagick would be a completely seperate tool from my program?

 
0
 

Ok, so I'm trying to make the IJG library but I have no idea what to do after I have jconfig.h.

 
0
 

Which compiler are you using? They do have a makefile for VC++ version 10. If you have cygwin, etc. you can use the build instructions for *nix.

 
1
 

If you have support to MFC library then you can use CImage class. Its very easy to saving image as jpeg using CImage. Just pass handle to bitmap to CImage or load it from hard drive. Call Save function and specify jpeg as saving type.

 
0
 

If you have support to MFC library then you can use CImage class. Its very easy to saving image as jpeg using CImage. Just pass handle to bitmap to CImage or load it from hard drive. Call Save function and specify jpeg as saving type.

True. There are also options available in .NET if you want to go on that adventure (since if you use the express editions, they don't have MFC)

 
0
 

I was able to solve my problem when I found this code, posting it here so others can use it:
http://www.codeguru.com/forum/showthread.php?t=476912&page=2

void gdiscreen()
{
	SYSTEMTIME SysTime;
	GetLocalTime(&SysTime);
	wchar_t filename[200];
	memset(filename,0,sizeof(filename));
	wsprintfW(filename,L"C:\\screen%02d:%02d:%02d h.jpeg",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
	
	using namespace Gdiplus;
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	{
		HDC scrdc, memdc;
		HBITMAP membit;
		scrdc = ::GetDC(0);
		int Height = GetSystemMetrics(SM_CYSCREEN);
		int Width = GetSystemMetrics(SM_CXSCREEN);
		memdc = CreateCompatibleDC(scrdc);
		membit = CreateCompatibleBitmap(scrdc, Width, Height);
		HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit);
		BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);

		Gdiplus::Bitmap bitmap(membit, NULL);
		CLSID clsid;
		GetEncoderClsid(L"image/jpeg", &clsid);
		bitmap.Save(filename, &clsid);

		SelectObject(memdc, hOldBitmap);

		DeleteObject(memdc);

		DeleteObject(membit);

		::ReleaseDC(0,scrdc);
	}

	GdiplusShutdown(gdiplusToken);
}
Question Answered as of 3 Years Ago by jonsca, daviddoria and ashishchoure
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article