Re: Drawing Text on Image object with GDI+

Tech-Archive recommends: Fix windows errors by optimizing your registry



<marcusadeleon@xxxxxxxxx> wrote in message news:99bf821c-6de2-43c4-bf73-945b2e7cc27a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 5 Mar, 23:59, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospam> wrote:

Yes, that's what I did, but when I saved the bitmap to the hard drive
there is no text. Is there anything else I have to do to save the
image after I draw on it and keep it?

This works for me:

Bitmap TextBitmap(640, 480, PixelFormat24bppRGB);

Graphics TextGraphics(&TextBitmap);

SolidBrush whiteBrush(Color(255, 255, 255, 255));
TextGraphics.FillRectangle(&whiteBrush, 0, 0, 320, 240);

Gdiplus::Font myFont(L"Arial", 40);
PointF origin(0.0f, 0.0f);
SolidBrush blackBrush(Color(255, 0, 0, 0));
TextGraphics.DrawString(L"Sample Text", 11, &myFont, origin, &blackBrush);

CLSID bmpClsid;
GetEncoderClsid(L"image/bmp", &bmpClsid);
TextBitmap.Save(L"e:\\TextImage.bmp", &bmpClsid);


Mark

--
Mark Salsbery
Microsoft MVP - Visual C++


.



Relevant Pages