PDA

View Full Version : Image Viewer in VBA?



bigJD
05-02-2012, 08:14 PM
Is it possible to create a simple image viewer in vba? Im thinking of a picture box with some controls and a drive/data list to view the file in the directory and if click the image will load on picture box. Is this possible? Thanks

Bob Phillips
05-03-2012, 12:41 AM
What would drive which picture is shown? You could load all picture filenames into an array, and use a slider to pick up the next in the array.

bigJD
05-03-2012, 01:07 AM
http://i45.tinypic.com/be7vbn.png

It looks like something like this one.
Can you please show me some demo to start on?
Thanks

Bob Phillips
05-03-2012, 01:23 AM
What looks something like this one? How does that picture answer what I said?

bigJD
05-03-2012, 01:32 AM
What would drive which picture is shown?
Sorry I didnt catch that. I mean I was trying to picture out what I mean on that foto.

bigJD
05-03-2012, 01:52 AM
could you show me some example xld sir? Thanks.

Bob Phillips
05-03-2012, 03:13 AM
Here is an example of what I was suggesting.

bigJD
05-03-2012, 07:03 PM
Yes that xld something like that but with list of images inside the directory/path given. Would that be integrated to form rather than in the worksheet?

Thanks so much for the help :)

bigJD
05-04-2012, 10:35 PM
xld can you help me again to integrate it in the form instead of inside the worksheet. I was trying but the foto is not showing up.

bigJD
05-06-2012, 09:26 PM
Anyone can help me implementing it to form rather than in the worksheet? Thanks :)

Bob Phillips
05-07-2012, 02:28 AM
Try this

bigJD
05-08-2012, 08:04 PM
Oh my thats perfect xld. I wonder if we could add zoom in and zoom out in the image? This is really what i need :)
Thanks so much :)

defcon_3
05-26-2012, 01:45 AM
@xld
I tried your Image viewer it look nice but I encounter some problem, After sometimes the image was loaded it stuck on a single image even you click some items on the list, even if you reload the image dir it will be stuck on a certain photo, the solution was to re run the form. What could be the cause of that? A memory issue? Would be better as well if it can be zoomed, a very potential project.

jolivanes
05-26-2012, 10:11 PM
And here is another viewer if you want.

defcon_3
05-27-2012, 11:04 PM
I have modified the your image viewer jolivanes answering OP request as well to make image appear on the list. But there are strange things that happen which I do not know which causes error. If I browse a folder and click item on the list it says Unable to load image but when I open the Image Viewer posted by jolivanes and load an image and return to the Image Viewer I modified and broswe again a folder and click an Item in the list the image will show. So I dont know why I have to load first the image viewer of jolivanes to make my modified image viewer works. Any idea about this issue? I attached the Image Viewer I modified.

bigJD
05-27-2012, 11:37 PM
jolivanes (http://www.vbaexpress.com/forum/member.php?u=1993) and DefCon thanks but it cant load the image no error promt just the message box stating "Unable to load image"

defcon_3
05-27-2012, 11:43 PM
I think you have to read my above post. Load some image first with the viewer jolivanes (http://www.vbaexpress.com/forum/member.php?u=1993) created the try to browse the again on my mod and click item on the list and youll see image will load. Strange huh.

jolivanes
05-28-2012, 09:13 AM
Here is another picture viewer that works in excel 2003.
Does not work in 2007 (Application.Filesearch)

If someone makes it work in 2007, I would not mind getting a copy.

Thanks

bigJD
05-28-2012, 07:47 PM
Thanks for all the help I got it sorted out :)

defcon_3
05-28-2012, 11:03 PM
@jolivanes, I dont know if your aware of this error. i combined your code with the code I added. Using the left pane by browsing per folder, will cause returns to null and causes error, when the item is loaded try browsing per file with the below browser and try to click again to the items and it will now load the images. After sometime it will again result error and you need to reload any single file again to make the item load again. I wonder what causes this error. I appreciate your help but unfortunately Im trying to make it work on 2007 version.

I guess the error reside on this area


Sub LoadImage(Name As String)

If Dir(Name) <> "" Then
With Image1
.AutoSize = True
.Picture = LoadPicture(Name)
m_sngHeight = .Height
m_sngWidth = .Width
.AutoSize = False
.PictureSizeMode = fmPictureSizeModeStretch
m_sngZoom = 1
.Left = 1
.Top = 1
End With
SetZoom m_sngZoom
Else
MsgBox "Unable to load image " & Chr(10) & Name, vbExclamation
End If
End Sub



Private Sub cmdDir_Click()
Dim MyFolder As String
Dim MyFile As String

With Application.FileDialog(msoFileDialogFolderPicker)

If .Show = -1 Then

lstImages.Clear

txtDir.Text = .SelectedItems(1)
MyFile = Dir(.SelectedItems(1) & "\*.jpg")
Do While MyFile <> ""

lstImages.AddItem MyFile
MyFile = Dir
Loop
End If
End With
End Sub


I guess it has something to do with the dir why image returns null on Load Image. Any ideas?

jolivanes
05-29-2012, 08:02 AM
Works fine for me using the button at the right top corner.