Jump to content

newbie- image downloader

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
34 replies to this topic

#1
Guest_yoda855_*

Guest_yoda855_*
  • Guests
i would like to create a program to replace Win XP's camera and scanner wizard. i want a program that will get the filenames from a specified folder on a memory card, then display 1 pic at a time. for each pic, give choice to copy to 1 of few folders and move to different folder on memory card. there will also be choice to copy to Other... folder or to skip file.

i have taken a class in programming in c in a consol window. i have also downloaded Microsoft Visual Basic 2005 Express Edition, but i don't know the syntax or commands to perform what i want

#2
Guest_yoda855_*

Guest_yoda855_*
  • Guests
here is what my program looks like so far

Quote

Sub Myfirstsub()
Dim pic As String
getfiles H:\\DCIM\\IMAGE102\

End Sub

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
copyfile pic to C:\Documents and Settings\Owner\My Documents\My Pictures\Family\
movefile pic to H:\DCIM\IMAGE101\
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
copyfile pic to C:\Documents and Settings\Owner\My Documents\My Pictures\Billy\
movefile pic to H:\DCIM\IMAGE101\
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
copyfile pic to C:\Documents and Settings\Owner\My Documents\My Pictures\Crossroads\
movefile pic to H:\DCIM\IMAGE101\
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

End Sub
End Class


#3
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
I assume the actual code in the functions is psuedo-code or comments, as I don't think that'll compile....

Anyway, without writing it out, it's a little tough to give exacts...but here's some pointers of the BCL classes you'll want to look at.

To display a pic: I think a PictureBox should do the trick...Just load it with a filename.
To move/copy/delete files: The IO.File namespace has methods for all these I think. They should be pretty simple.

The interesting part would be detecting when the camera is hooked up. You *might* be able to set up a FileSystemWatcher to watch the drive letter it shows up as - but I wouldn't be surprised if it throws an exception if the drive isn't there.

The only other way I can think of right now would involve subscribing to PnP events. But I'm not sure how to do that....

#4
Guest_yoda855_*

Guest_yoda855_*
  • Guests

brackett said:

I assume the actual code in the functions is psuedo-code or comments, as I don't think that'll compile....
i got the code by dragging the pieces into the design window and then adding code that i thought would make it do what i wanted

Quote

Anyway, without writing it out, it's a little tough to give exacts...but here's some pointers of the BCL classes you'll want to look at.

To display a pic: I think a PictureBox should do the trick...Just load it with a filename.
To move/copy/delete files: The IO.File namespace has methods for all these I think. They should be pretty simple.
i put a picturebox in the program, but how would i change the picture displayed after each click

Quote

The interesting part would be detecting when the camera is hooked up. You *might* be able to set up a FileSystemWatcher to watch the drive letter it shows up as - but I wouldn't be surprised if it throws an exception if the drive isn't there.

The only other way I can think of right now would involve subscribing to PnP events. But I'm not sure how to do that....
i'm not worried about detecting when the camera is hooked up. i can just run from the start menu if necessary

#5
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
Well code like this:

copyfile pic to C:\Documents and Settings\Owner\My Documents\My Pictures\Family\

isn't going to compile...You need to change that to something like:

IO.File.Copy(pic, "C:\Documents and Settings\Owner\My Documents\My Pictures")

If you really want to do it right, you should use the GetSpecialFolders call to get the location of the currently logged on user's My Docs instead of hardcoding it.

As for loading the pic box, I don't have docs in front of me right now, but I think there's a Load or Filename property that you just pass in the path to your pic. After each click, you'd just change that property.

You could go for thumbnails as well...I think you can just create a new Bitmap and passing it the new size you want. Check codeproject.com to see if there's any samples - things like thumbnails are pretty popular there, so I'd suspect you'll find something.

#6
Guest_yoda855_*

Guest_yoda855_*
  • Guests
i've worked on this some more but now i'm stuck
here's my program so far http://wheelersphoto...s.com/Form1.txt
1. in the For loop, after i load the picture, how do i make it wait for a button to
be pressed to continue
2. how do i define pic globaly
3. how do i make the Other . . . button (button7) open the SaveFileDialog

i also get an error saying that the function is not in a valid namespace

#7
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
So, you have a function and a class named GetFiles? That is all I can figure since you call GetFiles several times from the GetFiles function and you even call functions of it (getfiles.count).

To create a pause you can do a system.application.dowhile until a button is pressed and a variable turns true or you can remove the for loop and everytime the continue button is pressed it is incrimented and loads the next picture.

I'm not sure about defining globably in VB. I know in C++ and C# you just declare it above the class definition and functions.

Also not sure about VB but C++ and C# have a SaveFileDialog that you add to the project. Once added you go SaveFileDialog.ShowDialog()

#8
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts

yoda855 said:

i've worked on this some more but now i'm stuck
here's my program so far http://wheelersphoto...s.com/Form1.txt
1. in the For loop, after i load the picture, how do i make it wait for a button to
be pressed to continue
2. how do i define pic globaly
3. how do i make the Other . . . button (button7) open the SaveFileDialog

i also get an error saying that the function is not in a valid namespace

1. If you mean any button, then you could do a MessageBox.Show() and that'd block until the user clicked. Otherwise, you'd need to spin off that GetFiles method into a new thread, and do some synchronization to block on a button click on the form...I don't think you want to go there. If you want them to click a button on the form, I think you'll need to change your design.

2. I'm not sure what you mean by defining pic globally? Do you mean the currently loaded filename? You can just put a "Private picturePath as String" right underneath the class definition ("Public Class Form1"). Use that to store the path of the picture you're showing.

3. fileDialog.ShowDialog()

4. Move the GetFiles function into the class.

Just a couple of observations:
- You should really be doing Option Strict On and Option Explicit On. It'll make it a little tougher, in that you have to explicitly declare and cast things, but it's a much better way of programming. Just put those 2 lines at the top of your file.
- I'm not a VB6 guy, but it looks like you're using a good bit of VB6 stuff. It'll work, but if you're learning, why not go ahead and learn the .NET stuff. Get rid of the Microsoft.VisualBasic reference.
- I'm not sure what you're doing with GetFiles(). I don't see it being called from anywhere, and even if it was, you'll just be looping through the pics. I think what you probably want to do is have the collection of picturePaths as a member variable, and then cycle through them when the PictureBox is clicked.


Public Class Form1

 	' This will hold our collection of picture paths.

 	' We don't need to use a Collection object...a String array will work fine for our needs

    Private pictures as String()

    Private selectedIndex as Integer = -1

    

    ' Return all files in the selected directory

    Private Function GetFiles(ByVal filespec As String) As String()

	    ' Generally, it's ugly to assign the function name to your return

	    ' Non VB guys won't understand it, and VB guys won't like it

	    

	    ' Use the framework. There's a built in class to get file names from a directory.

	    ' Less code written = less code to maintain

	    Return System.IO.Directory.GetFiles(filespec)

	End Function

	

	' Copy the selected picture to copyToPath, and move it to moveToPath

	Private Sub CopyAndMove(copyToPath as String, moveToPath as String)

		' The PictureBox stores the path of the loaded picture

		' Alternatively, we could have gotten it by looking at our array

		' with pictures(selectedIndex)

		IO.File.Copy(PictureBox1.ImageLocation, copyToPath)

		IO.File.Move(PictureBox1.ImageLocation, moveToPath)

	End Sub


	Private Sub LoadNextPicture()

		' Use selectedIndex to keep track of where we are in the pictures array

    	If pictures.Length >= (selectedIndex + 1) Then

    		' At least 1 more picture left

    		PictureBox.Load(pictures(selectedIndex + 1))

    		selectedIndex += 1

        Else

        	MessageBox.Show("No more pictures.")

        	selectedIndex = -1

        End If

	End Sub

	

	' Load our pictures into the array and display first picture

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		' I'm not sure where you're getting the file path from...I'll just hard code it here

		Const PICPATH as String = "H:\DCIM"

		pictures = GetFiles(PICPATH)

		' load first pic to PictureBox

		LoadNextPicture()

	End Sub


    ' You should rename your eventhandlers to match your renamed buttons

    ' Save to Family

    Private Sub Family_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Family.Click

    	CopyAndMove("C:\Documents and Settings\Owner\My Documents\My Pictures\Family", "H:\DCIM\IMAGE101")

    End Sub


    ' Save to Billy

    Private Sub Billy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Billy.Click

		CopyAndMove("C:\Documents and Settings\Owner\My Documents\My Pictures\Billy", "H:\DCIM\IMAGE101")

    End Sub


    ' Save to Crossroads

    Private Sub Crossroads_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Crossroads.Click

        CopyAndMove("C:\Documents and Settings\Owner\My Documents\My Pictures\Crossroads", "H:\DCIM\IMAGE101")

    End Sub


    ' Exit app

    Private Sub Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit_.Click

        End

    End Sub


    ' Switch to next picture

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    	LoadNextPicture()

    End Sub


    ' Save to custom path

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Other.Click

    	' SaveFileDialog implements IDisposable, so we should wrap it in

    	' Using/End Using to make sure it is cleaned up properly

        Using fileDialog as New SaveFileDialog()

	        ' Add a filter so it know what types of files to show

	        fileDialog.Filter = "Image Files (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*)"

	        If fileDialog.ShowDialog() = DialogResult.OK Then

	        	' User selected a path

	        	CopyAndMove(fileDialog.FileName, "H:\DCIM\IMAGE101")

	        End If

	    End Using

    End Sub

End Class


I don't know how well the formatting came out there, but hopefully it gives you an idea. I didn't try to compile it either, so there could be compilation errors - but it should give you a start.

#9
Guest_yoda855_*

Guest_yoda855_*
  • Guests
i got most of the function code from a different website (can't remember which one)
is there a better way to perform the task of the function?
(collect filenames, load picturebox, and pass file path to buttons)

this is the current status of my program

Function GetFiles(ByVal filespec As String) As Collection

    Dim filename As String

    Getfiles = New Collection

    filename = Dir$(filespec)

    Do While Len(filename)

        GetFiles.Add(filename), filename

        filename = Dir$(filespec)

    Loop

    Dim numb As Integer

    numb = GetFiles.Count

    Dim i As Integer

    i = 1


    For i = 1 To numb

        Label1.Caption = Label1.Caption + i + "of" + numb

        Form1.PictureBox1.Load(Getfiles 1)

        Dim  pic = Getfiles i

        System.Application.Dowhile(Form1.Family.Click = False And Form1.Billy.Click = False And Form1.Crossrads.Click = False And Form1.AWANA.Click = False And Form1.Other.Click = False And Form1.Skip.Click = False)

        i = i + 1

    Next

End Function


Public Class Form1


    Private Sub Family_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Family.Click

        IO.File.Copy(pic, "C:\Documents and Settings\Owner\My Documents\My Pictures\Family")

        IO.File.Move(pic, "H:\DCIM\IMAGE101")

    End Sub


    Private Sub Billy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Billy.Click

        IO.File.Copy(pic, "C:\Documents and Settings\Owner\My Documents\My Pictures\Billy")

        IO.File.Move(pic, "H:\DCIM\IMAGE101")

    End Sub


    Private Sub Crossroads_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Crossroads.Click

        IO.File.Copy(pic, "C:\Documents and Settings\Owner\My Documents\My Pictures\Crossroads")

        IO.File.Move(pic, "H:\DCIM\IMAGE101")

    End Sub


    Private Sub AWANA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AWANA.Click

        IO.File.Copy(pic, "C:\Documents and Settings\Owner\My Documents\My Pictures\Awana Lauralglen 2006")

        IO.File.Move(pic, "H:\DCIM\IMAGE101")

    End Sub


    Private Sub Other_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Other.Click

        SaveFileDialog1.ShowDialog()

    End Sub


    Private Sub Skip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Skip.Click


    End Sub


    Private Sub Exit__Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Exit_.Click

        End

    End Sub

End Class



#10
Guest_yoda855_*

Guest_yoda855_*
  • Guests
thanks bracket
the code compiled with only a couple edits
there are still a couple problems with it though.
1. my camera takes pictures at 2048 x 1536 and the image is too large for the
window, even maximized. is it possible to make the image fit the window?
2. when i click on a button i get the following error
System.IO.IOException was unhandled
Message="The target file "C:\Documents and Settings\Owner\My
Documents\My Pictures\Family" is a directory, not a file."

#11
Crane

Crane

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts
1) You should be able to set the picturebox property to stretch. This will cause the image to shrink or expand to the size of the picture box.

2) I'm not sure since I didn't look into the code above but it looks like you are trying to load a directory as a picture in the picturebox.

#12
Guest_yoda855_*

Guest_yoda855_*
  • Guests
the strech property did work
the picture box should be loading the image passed to it
the problem is the copytopath and movetopath commands point to a directory, but the compiler says it must point to a filename
how can i make it do this and keep the original filename, just change directories
also, for the Other button, in the SaveFileDialog box, how do i make it display the original filename, but start in the My Pictures folder