Drawing on a jpg file in a picturebox.

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Resolved...Drawing on a jpg file in a picturebox.

I have simplified this project down to its basic function:
Load a jpg file into a picturebox - draw graphics on it - save it.

I'm confused on how to create the file to be saved from the background jpg and the graphics I have drawn over the top of it.
I need a button click event to save a jpg with the numbered circles on it.

See the one form project.

Thanks for looking...
 

Attachments

  • PrintMarking.zip
    25.1 KB · Views: 43
Last edited:
Two approaches:
- If once marked a point is considered permanent you might as well draw directly on image (without saving the points). This also saves some drawing operations. Take the image from picturebox, creategraphics on the image, draw to the image with the graphics object, reassign image to picturebox for display.
- If storing the points is important for points management later you're good for now, when saving you do the same thing as in paint handler (and similar to above sketch), take image and creategraphics, draw all the points and save. You can also move out the code in paint event and make a Sub method that takes a graphics object as parameter, the routine could be used both for drawing to picturebox and drawing to image.
 
having trouble with the commands:

having trouble with the commands:

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim BluePrint1 As Graphics
        BluePrint1 = Graphics.FromImage(PictureBox1.Image)
        [COLOR=SeaGreen]'draw the circles here[/COLOR]
        SaveFileDialog1.Filter = "JPG Files|*.jpg|All Files|*.*"
        SaveFileDialog1.FilterIndex = 0
        If SaveFileDialog1.ShowDialog = DialogResult.OK Then
[COLOR=Red]            'no idea for this code
            'set PictureBox1.Image to BluePrint1?
            'Save as a jpeg (SaveFileDialog1.FileName)[/COLOR] 
        End If
    End Sub

P.S. I do not want the circles to be permanent, I hope to build in rollback and other features before committing the drawing.
 
examples:
VB.NET:
dim img as image = picturebox1.image
BluePrint1 = graphics.fromimage(img)
BluePrint1.draw...
BluePrint1.dispose
img.save and/or picturebox1.image = img
 
Back
Top