Save GDI+ as image

  • Thread starter Thread starter MAY
  • Start date Start date
M

MAY

Hi,

I drew some lines on a form and i want convert these lines into a bitmap.
How can i do that?


MAY
 
it's actually best to draw on a Image/Bitmap and put that image on the form.

pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Image bmp = pictureBox1.Image;
Graphics g = Graphics.FromImage(bmp);

//Edit bmp
g.FillRectangle(new SolidBrush(Color.White), 0, 0, pictureBox1.Width,
pictureBox1.Height);
for(int I=0; I < pictureBox1.Width; I+)
g.DrawLine(new Pen(Color.Black), pictureBox1.Width - I, 0, 0, I);

//Display bmp
pictureBox1.Image = bmp;


then to save the image all you'd have to do is make the image public or
something and

bmp.SaveTo("C:\stuff.png");

Hope that helps
 
Thx for help..

as this form will dynamic create drawing stuffs in run time thus cant change
picturebox.img. is there have other alternatives?


MAY


"Scatropolis" <[email protected]> ???
???...
it's actually best to draw on a Image/Bitmap and put that image on the form.

pictureBox1.Image =ew Bitmap(pictureBox1.Width, pictureBox1.Height);
Image bmp =ictureBox1.Image;
Graphics g =raphics.FromImage(bmp);

//Edit bmp
g.FillRectangle(new SolidBrush(Color.White), 0, 0, pictureBox1.Width,
pictureBox1.Height);
for(int I= I < pictureBox1.Width; I+)
g.DrawLine(new Pen(Color.Black), pictureBox1.Width - I, 0, 0, I);

//Display bmp
pictureBox1.Image =mp;


then to save the image all you'd have to do is make the image public or
something and

bmp.SaveTo("C:\stuff.png");

Hope that helps
 
MAY said:
Thx for help..

as this form will dynamic create drawing stuffs in run time thus cant change
picturebox.img. is there have other alternatives?

// Create an image 100 x 100 pixels
Image image = new Bitmap(100, 100);

// Get the Graphics object
using (Graphics g = Graphics.FromImage(image))
{
// Do your drawing here....
}
image.Save(filename, System.Drawing.Imaging.ImageFormat.Gif);
 
Thx guys..... i got it!

Ed Courtenay said:
MAY said:
Thx for help..

as this form will dynamic create drawing stuffs in run time thus cant change
picturebox.img. is there have other alternatives?

// Create an image 100 x 100 pixels
Image image = new Bitmap(100, 100);

// Get the Graphics object
using (Graphics g = Graphics.FromImage(image))
{
// Do your drawing here....
}
image.Save(filename, System.Drawing.Imaging.ImageFormat.Gif);
MAY


"Scatropolis" <[email protected]> ???
???...
it's actually best to draw on a Image/Bitmap and put that image on the form.

pictureBox1.Image =ew Bitmap(pictureBox1.Width, pictureBox1.Height);
Image bmp =ictureBox1.Image;
Graphics g =raphics.FromImage(bmp);

//Edit bmp
g.FillRectangle(new SolidBrush(Color.White), 0, 0, pictureBox1.Width,
pictureBox1.Height);
for(int I= I < pictureBox1.Width; I+)
g.DrawLine(new Pen(Color.Black), pictureBox1.Width - I, 0, 0, I);

//Display bmp
pictureBox1.Image =mp;


then to save the image all you'd have to do is make the image public or
something and

bmp.SaveTo("C:\stuff.png");

Hope that helps


--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
 
Back
Top