N
Nitin
Hi!
I've been trying to draw in a PictureBox and save the resulting image
to a Bitmap object that I save to a file on disk. Unfortunately, I
can't seem to get the elements that I'm drawing to appear in the file.
To make sure that I'm getting something that actually is from the
PictureBox, I set the background color of the PictureBox and that's
all that appears in the file (I use Windows Preview).
Below is the code extract that I used for the program:
The PictureBox is on a form and is visible with the drawing when I
execute the code.
I'd appreciate any help with finding the bug.
-NiTiN
I've been trying to draw in a PictureBox and save the resulting image
to a Bitmap object that I save to a file on disk. Unfortunately, I
can't seem to get the elements that I'm drawing to appear in the file.
To make sure that I'm getting something that actually is from the
PictureBox, I set the background color of the PictureBox and that's
all that appears in the file (I use Windows Preview).
Below is the code extract that I used for the program:
Code:
pictureBox1.BackColor = Color.AntiqueWhite;
Graphics gfx = pictureBox1.CreateGraphics();
gfx.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Pen pn = Pens.Black;
Pen pnAlt = Pens.Blue;
gfx.DrawLine(pn, 0, 0, 80, 80);
gfx.DrawPie(pn, 80, 80, 100, 100, 0, 14);
gfx.DrawPie(pnAlt, 80, 80, 100, 100, 15, 14);
gfx.Flush();
gfx.Dispose();
Bitmap bmp = new Bitmap(pictureBox1.Width,
pictureBox1.Height);
pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0,
pictureBox1.Width, pictureBox1.Height));
bmp.Save("img1.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg);
break;
The PictureBox is on a form and is visible with the drawing when I
execute the code.
I'd appreciate any help with finding the bug.
-NiTiN