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

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?

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

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.

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.

commented: Good idea +5

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)

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);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.