Save drawing to an image in VB.NET
-
Hey, I've drawn a drawing in form. For example I have drawn line or circle or ... My problem is I want to save this drawing as image file. Can anybody give me an idea how I can do this? I appreciate your help. hsprasain
Draw it onto an Image or Bitmap, then call it's Save method. If you're already drawing in the Paint event, then just create a member Bitmap, draw onto that, and draw that in your Paint event.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "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 )
-
Hey, I've drawn a drawing in form. For example I have drawn line or circle or ... My problem is I want to save this drawing as image file. Can anybody give me an idea how I can do this? I appreciate your help. hsprasain
In my code I creat a piechart. What I have done is stripped down the code to show you what goes where (This code will not work as it needs declarations and values...). This code will in effect make the picture 'stick' to the form - so that it does not get erased as you move the form. Panel1 is where the piechart is being drawn. Width and Height are variables you need to set to the size of the picture you want. You will also need to include the Panel1.CreateGraphics.DrawImage(b1, 0, 0) command in the Paint event of the objetct you are drawing onto - in fact this is where the magic of this method is... Give this a go and good luck... Regards Guy Cambridge UK
Public b1 As Bitmap Public g1 As Graphics b1 = New Bitmap(Width, Height, Panel1.CreateGraphics()) g1 = Graphics.FromImage(b1) g1.DrawPie(Pen:=myPen, rect:=New Rectangle _ (x:=x + XAdjust, y:=y + yAdjust, Width:=Width, Height:=Height), _ startAngle:=startPos, sweepAngle:=sweep)
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint Panel1.CreateGraphics.DrawImage(b1, 0, 0) End Sub
You always pass failure on the way to success.