Photo capture

I want my program to take an image of the screen..

Page 1 of 1

7 Replies - 6227 Views - Last Post: 20 February 2009 - 05:02 AM Rate Topic: -----

#1 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Photo capture

Posted 19 February 2009 - 05:47 AM

I want my program to take an image of the screen every second or so acording to a timer i have the screen capture code but Im not sure on how to get the program to save the image to a directory without showing the save file dialog.

Save code
 Dim savefiledialog1 As New SaveFileDialog
		Try
			savefiledialog1.Title = "save File"
			savefiledialog1.FileName = " *.bmp "
			savefiledialog1.Filter = "Bitmap |*.bmp* "
			If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
				PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
			End If
		Catch ex As Exception
		End Try



this is the code for putting the image in the image box if possible could i have some help so that i could go straight form this code to the save without using a separate sub for it.

  Dim bounds As Rectangle
		Dim screenshot As System.Drawing.Bitmap
		Dim graph As Graphics
		bounds = Screen.PrimaryScreen.Bounds
		screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555)
		graph = Graphics.FromImage(screenshot)
		graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)



picturebox1 is the box that the image is held in but i would prefere not to have it there and like i said before as soon as the screenshot is taken i would like it to be saved to a directory of the users choice. B)

If possible i would like each image to be named after the time it was taken.

This post has been edited by Asscotte: 19 February 2009 - 06:45 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Photo capture

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

Re: Photo capture

Posted 19 February 2009 - 08:17 AM

Try something like
Save code
 Dim NameOfFile As string=" 'The location of the file.
Try
PictureBox1.Image.Save(NameOfFile )
Catch ex As Exception
End Try


Was This Post Helpful? 0
  • +
  • -

#3 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Photo capture

Posted 19 February 2009 - 01:18 PM

Thanks I will try. :D
Was This Post Helpful? 0
  • +
  • -

#4 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Photo capture

Posted 19 February 2009 - 01:27 PM

Thats not working. How would I have to use it for it to work?
Was This Post Helpful? 0
  • +
  • -

#5 TEH  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 152
  • Joined: 30-January 08

Re: Photo capture

Posted 20 February 2009 - 02:26 AM

At the first thing in your program declare a variable filename as string then show dialog where user select the save folder and save that folder to variable, then you need only that line :
 
	 PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)

'Chance it to this

	 PictureBox1.Image.Save(variable.tostring & datetime.now, System.Drawing.Imaging.ImageFormat.Bmp)



I am not sure about code but at least you get an idea for that.
Was This Post Helpful? 0
  • +
  • -

#6 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Photo capture

Posted 20 February 2009 - 03:01 AM

Thanks I kind off mixed the two ideas and came up with this...
		If CheckBox3.Checked Then
			Dim fileDir1 As String = filedir.Text
			Dim frame0 As String = Filenum.Text
			Dim img0 As String = filetype.Text

			Filenum.Text = Filenum.Text + 1
			Try
				If CheckBox4.Checked Then
					Playback.Show()
					Playback.PictureBox1.Load(fileDir1 + frame0 + img0)
				Else
					Me.PictureBox1.Load(fileDir1 + frame0 + img0)
				End If
			Catch
			End Try

		Else
			Dim screensize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
			Dim bmp As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
			Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)

			g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screensize)

			Dim filedir0 As String = filedir.Text
			Dim frame As String = Filenum.Text
			Dim IMG As String = filetype.Text

			Filenum.Text = Filenum.Text + 1

			bmp.Save(filedir0 + frame + IMG)


Its all within a timer and thats activated by a button. The varius textboxes control speed off picture taking (framerate) and directory that it is saved to and file type. Thanks soooo Much. B)
Was This Post Helpful? 0
  • +
  • -

#7 XavierMG  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 20-February 09

Re: Photo capture

Posted 20 February 2009 - 03:12 AM

I see you got it working but just for FYI. If you already know how to capture the screen and put it in a picturebox all you need is.

Picturebox1.Image.Save("c:\movies\pics\cap" & pNumber & ".png")

Or wherever you want to save it. On mine I have an auto incrementing number (with a timer like you) and use that to save each picture with a new name and I chose *.png format.

(Using VB.net 2008 Pro)
Was This Post Helpful? 0
  • +
  • -

#8 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Photo capture

Posted 20 February 2009 - 05:02 AM

yer the reason its not like that is that I am using it to construct a vauge storyboard of screen events so the rest is the comands for peicing it back together :) ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1