Results 1 to 19 of 19

Thread: Drawing shapes onto a pic box and saving the modified image

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    12

    Talking 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:
    1. Public Class Form1
    2.  
    3.     Private Sub LoadImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadImage.Click
    4.         With OpenFileDialog1
    5.             '.InitialDirectory = "C:\"
    6.             .Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
    7.             .FilterIndex = 4
    8.         End With
    9.  
    10.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    11.             PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
    12.             PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    13.             PictureBox1.BorderStyle = BorderStyle.Fixed3D
    14.         End If
    15.  
    16.     End Sub
    17.  
    18.     Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
    19.         With SaveFileDialog1
    20.             .InitialDirectory = Environment.SpecialFolder.Desktop
    21.             .Title = "Save As image file"
    22.             .Filter = "Portable Network Graphics (JPG/JPEG Format (*.JPG)|*.JPG|All files (*.*)|*.*"
    23.             .FilterIndex = 1
    24.             If .ShowDialog() = DialogResult.OK Then
    25.                 PictureBox1.Image.Save(.FileName)
    26.             End If
    27.         End With
    28.     End Sub
    29.  
    30.     Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    31.         Dim p As New System.Drawing.Pen(Color.Red, 1)
    32.         Dim g As System.Drawing.Graphics
    33.         Dim x As Integer
    34.         Dim y As Integer
    35.         x = MousePosition.X
    36.         y = MousePosition.Y
    37.         MousePosition.Offset(250, 600)
    38.         If crsrO.Checked Then
    39.             g = PictureBox1.CreateGraphics
    40.             g.DrawEllipse(p, x, y, 3, 3)
    41.         ElseIf crsrsq.Checked Then
    42.             g = PictureBox1.CreateGraphics
    43.             g.DrawRectangle(p, x, y, 3, 3)
    44.         End If
    45.     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
  •  



Click Here to Expand Forum to Full Width