Hi,
I am designing a paint brush type program…..for drawing area where I can draw something then I used pictureBox…..like as
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
g.DrawEllipse(p, e.X, e.Y, 5, 7);
in this program I can draw anything but when I want to save this drawing by the help of this command: pictureBox2.Image.Save(saveFileDialog1.FileName);
then an error occur : “NullReferenceExpection was unhandled !”
“Object reference not set to an instance of an object.”
I need your help………can anybody solve my problem
Thanks
zeeShan AnsariPosted Jun 27, 2007, 8:20 AM
Hi,
follwing code solve just half problem................means save only last ellipse ,but i want whole drawing
--------------------------------------------------------------
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Bitmap bmp = new Bitmap(pictureBox2.Width, pictureBox2.Height);
Graphics g = Graphics.FromImage(bmp);
Pen p = new Pen(Color.Red, 5);
g.DrawEllipse(p, e.X, e.Y, 5, 7);
}
---------------------------------------------------------------
and then ......... ... .
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image = bmp;
pictureBox2.Image.Save(saveFileDialog1.FileName);
}
-----------------------------------------------------------------
i think, there is something missing in
Graphics g = Graphics.FromImage(bmp);
or
pictureBox2.Image = bmp;
(like: pictureBox2.Image += bmp; but illegal )
-----------------------------------------------------------------
bmp or pictureBox does not update with previous condition
it always losing the previous ellipse and save the last drawn
ellipse
zeeShan AnsariPosted Jun 27, 2007, 5:40 AM
AlanPosted Jun 25, 2007, 2:50 PM
Bitmap bmp = new Bitmap(pictureBox2.Width, pictureBox2.Height);
Graphics g = Graphics.FromImage(bmp);
Pen p = new Pen(Color.Red, 5);
g.DrawEllipse(p, e.X, e.Y, 5, 7);
pictureBox2.Image = bmp;