Re: Scale bitmaps using GDI+
- From: Eric <Eric@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 19 Jan 2007 13:34:02 -0800
Bellow is the code that uses Graphics to obtain a scaled bitmap. But, the
result is only a blank bitmap with right dimension. Could you point out which
part I did wrong over there?
// create GDI+ bitmap from the original
Gdiplus::Bitmap GDIBmp(pOriginalBmpHeader, pOriginalBmpData);
// get the JPEG image encoder
CLSID imgClsid;
int nEncoderRc = GetGDIPlusEncoderClsid(L"image/jpeg", &imgClsid);
// create a graphics object from original bitmap
Gdiplus::Graphics GDIGrp(&GDIBmp);
// perform image scaling
Gdiplus::RectF rect(0, 0, m_dwNewWidth, m_dwNewHeight);
GDIGrp.DrawImage(&GDIBmp, rect);
HDC hGrahicDC = GDIGrp.GetHDC();
CDC MemDcDest;
MemDcDest.CreateCompatibleDC(CDC::FromHandle(hGrahicDC));
CBitmap bmpDest;
bmpDest.CreateCompatibleBitmap(&MemDcDest, m_dwNewWidth, m_dwNewHeight);
// associate the new bitmap with dc
CBitmap* pOldBmp = MemDcDest.SelectObject(&bmpDest);
// copy the scaled bitmap from Graphics' DC
MemDcDest.BitBlt(0, 0, m_dwNewWidth, m_dwNewHeight,
CDC::FromHandle(hGrahicDC), 0, 0, SRCCOPY);
// create a new scaled GDI+ bitmap
Gdiplus::Bitmap* pBmpScaled = Gdiplus::Bitmap::FromHBITMAP((HBITMAP)bmpDest,
NULL);
// save to file
Gdiplus::Status stat = pBmpScaled->Save(szwFilePath, &imgClsid, NULL);
// clean up
MemDCDest.SelectObject(pOldBmp);
GDIGrp.ReleaseHDC(hDC);
Thanks!
Eric
"Michael Phillips, Jr." wrote:
DrawImage is not only for display. The Graphics object represents a drawing.
surface. That surface can be an image, metafile, display, printer, etc.
"Eric" <Eric@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:257B08E6-F899-4A46-B470-FE134D432B4A@xxxxxxxxxxxxxxxx
THe purpose of the scaling is not for display. I need to save the scaled
image in file as JPEG. That means I must bind the scaled image to a
Bitmai/Image object to do that.
Thanks!
Eric
"Michael Phillips, Jr." wrote:
Use the Graphics's method DrawImage to scale your image.
"Eric" <Eric@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9443F4FA-B556-42C1-9EF4-24A8D421D73B@xxxxxxxxxxxxxxxx
In one of my applications, I need to perform image scaling, then save
the
scaled image to a JPEG file. I can load the original image into a
bitmap/Image object, but, cannot find a method in these two classes to
do
the
scaling. Since there is no need to display it, I did not use Graphics
class.
Any ideas?
--
Thanks!
Eric
- Follow-Ups:
- Re: Scale bitmaps using GDI+
- From: Michael Phillips, Jr.
- Re: Scale bitmaps using GDI+
- References:
- Re: Scale bitmaps using GDI+
- From: Michael Phillips, Jr.
- Re: Scale bitmaps using GDI+
- From: Michael Phillips, Jr.
- Re: Scale bitmaps using GDI+
- Prev by Date: Re: Scale bitmaps using GDI+
- Next by Date: Re: Scale bitmaps using GDI+
- Previous by thread: Re: Scale bitmaps using GDI+
- Next by thread: Re: Scale bitmaps using GDI+
- Index(es):
Relevant Pages
|
Loading