1 Replies - 8611 Views - Last Post: 20 January 2011 - 08:50 AM Rate Topic: -----

#1 codezapper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-May 09

How to create graphics on an image in a picture box and save it to a f

Posted 25 May 2009 - 07:35 PM

I am creating an application where when I click on an image I need to mark the place using the x and y co-ordinates given by the click and then after marking I put a red dot/circle on that spot and then I need to save this image to a file including the dot/circle I marked. I have tried saving the image to the file but to no avail, I have been able to only save the PictureBox image and that doesn't include the graphics. It is only the base image. I have tried to save it as a bitmap but have not gotten anywhere with that either. It seems whenever I call the image.save it takes only the value of the underlying image and saves it. Can anybody help me with this? Thanks in advance
Private Sub BtnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCreate.Click
		pointmarked = False
		BtnCreate.Enabled = False
	End Sub

Private Sub Pic1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseDown
		If e.Button = MouseButtons.Left Then
				Dim tmpfilenam As String
				Dim temppic As Image
				TxtPntDesc.Text = "Mouse down at" + CStr(e.X) + " :" + CStr(e.Y)
				Beep()
					If pointmarked = True Then
					Else
						mkptx = e.X
						mkpty = e.Y
						DrawCircle(New Point(e.X, e.Y), 2, Pens.Black, Color.Red)
						pointmarked = True
						If directory.Exists(dirstr) Then
							tmpfilenam = filename + "a~tmp.jpeg"
							If file.Exists(dirstr + tmpfilenam) Then
								file.Delete(dirstr + tmpfilenam)
							End If
							temppic = Pic1.Image
							temppic.Save(dirstr + tmpfilenam)
							file.SetAttributes(dirstr + tmpfilenam, IO.FileAttributes.Hidden)
						End If
					End If
		End If
	End Sub

Private Sub DrawCircle(ByVal cp As Point, ByVal radius As Integer, ByVal Pencolor As Pen, ByVal coloring As Color)
		gr = Pic1.CreateGraphics
		rect = New Rectangle(cp.X - radius, cp.Y - radius, 2 * radius, 2 * radius)
		gr.DrawEllipse(Pencolor, rect)
		Dim coloredbrush As New SolidBrush(coloring)
		gr.FillEllipse(coloredbrush, rect)
	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: How to create graphics on an image in a picture box and save it to a f

#2 Guest_Peyika*


Reputation:

Re: How to create graphics on an image in a picture box and save it to a f

Posted 20 January 2011 - 08:50 AM

Have you tried using Graphics.FromImage (Pic1.Image) instead of Pic1.CreateGraphics

What u do is paint on the control...and late draw the image of the picturebox above.

If u use Graphics.fromimage, u modify the image of the picturebox directly, and late u can save it to where u want.
Was This Post Helpful? 0

Page 1 of 1