Well, you may have overlooked a point or two, so I'm repeating the
procedure.
All the drawing you are doing, do it directly on the Bitmap.
Whenever you need to refresh the screen or display the result of the
drawing, paste the Bitmap onto the PictureBox, using
Graphics.DrawImageUnscaled(Bitmap, x, y)
When you need to save the drawing to file, you just call Image.Save on the
Bitmap you use for drawing.
Bitmap bm;
public TestForm()
{
bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// If you aren't doing any drawing here you might just paste the Bitmap
// Graphics g = Graphics.FromImage(bm);
// g.DrawString("Hello World", Brushes.Red, this.Font, 5, 5);
// g.Dispose();
e.Graphics.DrawImageUnscaled(bm, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
bm.Save("test.jpg", ImageFormat.Jpeg);
}
private void DrawSomeStuff()
{
using(Graphics g = Graphics.FromImage(bm))
{
g.DrawString("Hello World", Brushes.Red, this.Font, 5, 5);
}
using(Graphics h = pictureBox1.CreateGraphics())
{
h.DrawImageUnscaled(bm, 0, 0);
}
}
(PS! code may contain typos as it is not tested)
On Mon, 14 Mar 2005 14:27:56 GMT, yaya via DotNetMonster.com
<fo***@DotNetMonster.com> wrote:
Sorry for the confusion, actually I have a blank picturebox initially,
and
my program will draw some points and lines...and lastly, when the save
button is clicked, the picture(points and lines) drawn will save into a
jpeg file. It works and a jpeg file was saved, but the image of the file
was a blank black image instead of what the program has drawn on the
picturebox. Are you clear now? Thankx...
--
Happy Coding!
Morten Wennevik [C# MVP]