|
-
Aug 25th, 2009, 04:58 PM
#1
Thread Starter
New Member
Drawing shapes onto a pic box and saving the modified image
Hi all,
The aim of my program is to load a picture into an pic box, then to be able to place multiple shapes on the picture in the pic box by clicking on the location where i want the shape. The type of shape will depend on the radio button which has been selected. Basically all i want is choice of X or O. (its not tic tac toe either!!)
At the end of it all i want to be able to save the image WITH the shapes on it, doesnt matter what format its in (gif, jpg, bmp) as long as it has color and i can see the original image with the shapes included.
I have made several attempts at this, and this is what i have so far. (I am brand new to VB and programming so i need all the help i can get)
I have hit a wall with how far previous examples can get me.
Thanks for your help
Heres my code so far
vb.net Code:
Public Class Form1 Private Sub LoadImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadImage.Click With OpenFileDialog1 '.InitialDirectory = "C:\" .Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg" .FilterIndex = 4 End With If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName) PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage PictureBox1.BorderStyle = BorderStyle.Fixed3D End If End Sub Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click With SaveFileDialog1 .InitialDirectory = Environment.SpecialFolder.Desktop .Title = "Save As image file" .Filter = "Portable Network Graphics (JPG/JPEG Format (*.JPG)|*.JPG|All files (*.*)|*.*" .FilterIndex = 1 If .ShowDialog() = DialogResult.OK Then PictureBox1.Image.Save(.FileName) End If End With End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click Dim p As New System.Drawing.Pen(Color.Red, 1) Dim g As System.Drawing.Graphics Dim x As Integer Dim y As Integer x = MousePosition.X y = MousePosition.Y MousePosition.Offset(250, 600) If crsrO.Checked Then g = PictureBox1.CreateGraphics g.DrawEllipse(p, x, y, 3, 3) ElseIf crsrsq.Checked Then g = PictureBox1.CreateGraphics g.DrawRectangle(p, x, y, 3, 3) End If End Sub
Last edited by Robbyod; Aug 25th, 2009 at 06:11 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|