When you need to save a rectangle in your program to a file
the im.Save( "c:\\image.jpg", ImageFormatJPEG); line determines the file format
#include//For Image
using namespace Gdiplus; //For Image
void BitmapUtils::SaveBitmapToFile(HDC hdc,CRect rect)
{
HDC hMemDC = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc,rect.right, rect.Height() + rect.bottom);
if (hBitmap)
{
HBITMAP hOld = (HBITMAP) SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, rect.right, rect.Height() + rect.bottom, hdc, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOld);
DeleteDC(hMemDC);
::ReleaseDC(NULL, hdc);
}
CImage im;
im.Attach(hBitmap);
im.Save( "c:\\image.jpg", ImageFormatJPEG);
}
0 תגובות:
Post a Comment