Graphic problem?
-
Hello everyone, how do I save and print a graphic created by GDI+, using C#? I just want to save and print the graphic not including the form where graphic was drawn. Thank!!!:)
This is how you save something. Lets just say the class UI is the user control that you want to save. Printing is a bit more complicated. I gotta go now, but if I come back and nobody has answered I will show you.
//Lets say this is the user control you want to save or print public class UI:System.Windows.Forms.UserControl { public void UI_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //code to paint to e.Graphics } public event PaintEventHandler paint = new PaintEventHandler(UI_Paint); public void Save() { //Pretty straightforward, get a new bitmap equal to the same size Bitmap b = new Bitmap(this.Width,this.Height,this.CreateGraphics()); PaintEventArgs pe = new PaintEventArgs(Graphics.FromImage(b),this.ClientRectangle); //raise the paint event but paint to the bitmap paint(this,pe); b.Save("filename",System.Drawing.Imaging.ImageFormat.Jpeg); } } }
You can save it to any format you want, there are quite a few you can pull from ImageFormat.