GDI+ and placing text inside a bitmap

J

Jeff

hey

asp.net 2.0

Below you see my code.

#1
How to place the text at the buttom right of the image? I mean how do I
calculate the x,y parameter of the DrawString method?

#2
How can I place the text vertically centered in the image. Also here I mean
how do calculate the x,y parameters of DrawString

MemoryStream ms = new MemoryStream(test.FileBytes);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
Bitmap img = new Bitmap(new Bitmap(image));

Debug.WriteLine("Height = " + img.Height.ToString());
Font font = new Font("Verdana", 12);
Graphics gfx = Graphics.FromImage(img);
gfx.DrawString("Hello World", font, Brushes.Black, 5, img.Height - 12);
img.Save(Response.OutputStream, ImageFormat.Gif);

(as you see in my code, I'm using font size 12. Then I thought it was a good
idea to subtract 12 from the height. But that didn't solve the problem -
half of the text was drawn below the image)

any suggestions?
 
B

bruce barker

normally you'd call MeasureString to get the bonding rect, then calc where to
draw.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top