picturebox-saving to file and cf 2.0

T

tony

Hi.

I need to do this things with pictureBox control

1.load bmp to the pictureBox ( i know)

2.write some text on the pictureBox with the graphic object (i guess its on
the OnPaint event)

3.SAVE THE **NEW** BMP TO FILE. (the main difficult )

Is there somthing new in cf 2.0 that can help to do this ? if not, and any
help with 2-3 will be appreciate.

thanking in adavnce.
 
C

Christian Resma Helle

2.write some text on the pictureBox with the graphic object (i guess its
on the OnPaint event)

You won't really be able to override the OnPaint for the PictureBox control.
But what you can do is to draw the text you want on the image that you will
load to the PictureBox. Try something like:

// pbPhoto = PictureBox control

if (no_image == null) {
no_image = new Bitmap(pbPhoto.Width, pbPhoto.Height);

using (Graphics g = Graphics.FromImage(no_image)) {
using (Font font = new Font(Font.Name, 14f, FontStyle.Bold)) {
SizeF size = g.MeasureString("My Sample Text", font);
g.DrawString(
"My Sample Text",
font,
new SolidBrush(Color.DarkGray),
(pbPhoto.Width - size.Width) / 2,
(pbPhoto.Height - size.Height) / 2);
}
}
}

pbPhoto.Image = no_image;
3.SAVE THE **NEW** BMP TO FILE. (the main difficult )

The Image class has a function called Save()
 

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