Graphics to File
-
How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!
-
How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!
Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? The
CreateGraphics
method creates aGraphics
object for drawing on the control. There is no specificCreateGraphics
method that creates aGraphics
object for drawing on the image in aPictureBox
. You are just drawing on the screen, that does not affect the image in thePictureBox
. You have to create aGraphics
object for the bitmap so that you can draw the graphics on the bitmap instead of on the screen.--- single minded; short sighted; long gone;
-
How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!
pmartike wrote:
pictureBox1.CreateGraphics();
To further clarify, you should never do this 1 - it's a waste of a picture box, the picture box does nothing 2 - if your form is obscured, what you drew will be erased Draw in your paint event, or create a Bitmap and assign it to the picture box. Draw on it first if you want to, and save it, if you want to do that.
pmartike wrote:
Bitmap bb = new Bitmap(pictureBox1.Image);
The issue here is that there is no image inside the picture box, you need to put one in there, and even if you do, CreateGraphics won't do anything to it. It's more like you are drawing on a layer above the control, a layer that is not permanent.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!
Hi, your & my problem both are same ,read my today(june,27) post "Problem about bitmap in Visual Studio C Sharp.NET ?" i solve my half problem by following code:
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;
*first read my post, if you get any solution then please inform me -
How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!
serialize it
-
Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? The
CreateGraphics
method creates aGraphics
object for drawing on the control. There is no specificCreateGraphics
method that creates aGraphics
object for drawing on the image in aPictureBox
. You are just drawing on the screen, that does not affect the image in thePictureBox
. You have to create aGraphics
object for the bitmap so that you can draw the graphics on the bitmap instead of on the screen.--- single minded; short sighted; long gone;
Thanks, you're right :) i solved the problem...
-
Hi, your & my problem both are same ,read my today(june,27) post "Problem about bitmap in Visual Studio C Sharp.NET ?" i solve my half problem by following code:
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;
*first read my post, if you get any solution then please inform mei can't find your post :( i resolved my problem too:
Bitmap bit = new Bitmap(244, 200); Graphics g = Graphics.FromImage(bit); g.DrawRectangle(WhitePen, 10,10, 100, 50); bit.Save("c:\\image.bmp");
Can you give a link with your post?