Jump to content
Sign in to follow this  
gertsolo

Picture Viewer and copier

Recommended Posts

gertsolo

Hey all,

I would like to make a small picture viewer based on this solution by Big_Daddy :

http://www.autoitscript.com/forum/index.ph...=0&p=366854

What I want to do is select a directory and put all the images files of that dir in an array.

I would then like to show those images in the viewer, one by one, by pressing previous and next.

I would also like to have to option (with a button) to copy the image that is currently viewed to another location.

The problem is that I am very new to this and not to familiar with arrays.

Is this possible and doable?

code so far:

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", True)

HotKeySet("=", "_Zoom")
HotKeySet("-", "_Zoom")

$oPreview = ObjCreate("Preview.Preview.1")
$MyDir = "D:\My_Documents\My Pictures"

$Location = FileSelectFolder("Please select a folder", $MyDir)
$FileList = _FileListToArray($Location)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

GUICreate("Picture viewer")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
GUISetState()

;$sFile = FileOpenDialog("Open Image", $Location, "Image files (*.bmp;*.jpg;*.jpeg)", 1)
$oPreview.ShowFile ($FileList[1], 1)

While 1
    Sleep(100)
WEnd

Func _Zoom()
    Switch @HotKeyPressed
        Case "-"
            $oPreview.Zoom (-1)
        Case "="
            $oPreview.Zoom (1)
    EndSwitch
EndFunc ;==>_Zoom

Func _Exit()
    Exit
EndFunc ;==>_Exit
Edited by gertsolo

The more you learn, the less you know.

Share this post


Link to post
Share on other sites
weaponx

This seems simple enough. I tried looking up the Preview object on MSDN but couldn't find anything.

There is a slideshow example using this object here:

http://www.autoitscript.com/forum/index.ph...=image++preview

If someone has a link to the member functions of this object, that would be great, I have no clue how to get the next / previous buttons working.

Edited by weaponx

Share this post


Link to post
Share on other sites
smashly

Hi, mild update to code you provided, uses keyboard arrow keys..

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{UP}", "Control")
HotKeySet("{DOWN}", "Control")
HotKeySet("{LEFT}", "Control")
HotKeySet("{RIGHT}", "Control")

$oPreview = ObjCreate("Preview.Preview.1")

$Location = FileSelectFolder("Please select a folder", "")
$FileList = _FileListToArray($Location)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

$n = 1

GUICreate("Picture viewer")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
$oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)
GUISetState()

While 1
    Sleep(100)
WEnd

Func Control()
    Switch @HotKeyPressed
        Case "{DOWN}"
            $oPreview.Zoom (-1)
        Case "{UP}"
            $oPreview.Zoom (1)
        Case "{LEFT}"
            If $n > 1 Then 
                $n -= 1
            Else
                $n = $FileList[0]
            EndIf
            $oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)         
        Case "{RIGHT}"
            If $n < $FileList[0] Then 
                $n += 1
            Else
                $n = 1
            EndIf
            $oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)
    EndSwitch
EndFunc

Func _Exit()
    Exit
EndFunc

Cheers

Share this post


Link to post
Share on other sites
weaponx

Smashly - I guess that works too, but you should use a different FileListArray function like FileListToArrayEx or else the script will freak out if there is a non-image file in that folder.

Share this post


Link to post
Share on other sites
gertsolo

Smashly - I guess that works too, but you should use a different FileListArray function like FileListToArrayEx or else the script will freak out if there is a non-image file in that folder.

Well, it doesn't exactly freak out, the viewer just gives the 'No preview available' error. I can live with that ;-)


The more you learn, the less you know.

Share this post


Link to post
Share on other sites
gertsolo

Just out of curiosity, how do I use the next and previous buttons in the viewer?

Can I add buttons on that dialog, or fake it by putting buttons over it?


The more you learn, the less you know.

Share this post


Link to post
Share on other sites
weaponx

Well I followed a link in this post (posted by lod3n):

http://www.autoitscript.com/forum/index.php?showtopic=40398

And downloaded Oakland ActiveX/COM Inspector

http://www.oaklandsoftware.com/product_com.../product_3.html

Which exposed these methods for the Preview object:

ActualSize

AttachInterfaces

BestFit

CtlShow

RaiseOnOnActualSizePress

RaiseOnOnBestFitPress

RaiseOnOnClose

RaiseOnonerror

RaiseOnOnPreviewReady

ShowFile

SlideShow

Zoom

There is an events list, but there are no events for the builtin navigation buttons. I'm guessing you have to pass a folder path or comma seperated string to activate these buttons.

Share this post


Link to post
Share on other sites
gertsolo

BTW,

when running the exe on vista I get an error:Variable must be of type 'Object'

Am I overlooking something?


The more you learn, the less you know.

Share this post


Link to post
Share on other sites
weaponx

Maybe they ditched that object in Vista.

The dependent dll is Windows\System32\shimgvw.dll

Do you have that file?

Share this post


Link to post
Share on other sites
gertsolo

Maybe they ditched that object in Vista.

The dependent dll is Windows\System32\shimgvw.dll

Do you have that file?

Yup, it's there.

When compiling this

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{UP}", "Control")
HotKeySet("{DOWN}", "Control")
HotKeySet("{LEFT}", "Control")
HotKeySet("{RIGHT}", "Control")
HotKeySet("{ENTER}", "Control")

$oPreview = ObjCreate("Preview.Preview.1")
$HomeDir = "Z:\Kodak Pictures"
$CopyDir = "Z:\Kodak Pictures\_Karin_print"

$Location = FileSelectFolder("Kies een map om te bekijken", $HomeDir)
$FileList = _FileListToArray($Location)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

$n = 1

GUICreate("Picture viewer")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
$oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)
GUISetState()

While 1
    Sleep(100)
WEnd

Func Control()
    Switch @HotKeyPressed
        Case "{DOWN}"
            $oPreview.Zoom (-1)
        Case "{UP}"
            $oPreview.Zoom (1)
        Case "{LEFT}"
            If $n > 1 Then
                $n -= 1
            Else
                $n = $FileList[0]
            EndIf
            $oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)   
        Case "{RIGHT}"
            If $n < $FileList[0] Then
                $n += 1
            Else
                $n = 1
            EndIf
            $oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)
        Case "{ENTER}"
            ConsoleWrite($FileList[$n]& @CR)
            FileCopy($Homedir & "\" &$FileList[$n],$CopyDir & "\" &$FileList[$n])
            
    EndSwitch
EndFunc

Func _Exit()
    Exit
EndFunc

I Get:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "\\fastdude\Backup_station\Picture_viewer.au3"

\\fastdude\Backup_station\Picture_viewer.au3 (29) : ==> Variable must be of type "Object".:

$oPreview.ShowFile ($Location & "\" & $FileList[$n], 1)

$oPreview^ ERROR

Edited by gertsolo

The more you learn, the less you know.

Share this post


Link to post
Share on other sites
weaponx

Okay. Well I haven't used Vista but something tells me it doesn't still use the Windows Picture and File Viewer. There was a security vulnerability in that object and maybe instead of fixing it they chucked it.

http://www.bleepingcomputer.com/forums/topic39047.html

Maybe the dll jsut isn't being registered by default, you can try registering it.

1. Click Start > Run

2. regsrvr32 shimgvw.dll

Then try your script.

Share this post


Link to post
Share on other sites
gertsolo

Okay. Well I haven't used Vista but something tells me it doesn't still use the Windows Picture and File Viewer. There was a security vulnerability in that object and maybe instead of fixing it they chucked it.

http://www.bleepingcomputer.com/forums/topic39047.html

Maybe the dll jsut isn't being registered by default, you can try registering it.

1. Click Start > Run

2. regsrvr32 shimgvw.dll

Then try your script.

Dllname was loaded, but the DLLRegisterServer entry point was not found

Then copied it to the AutoIt working dir, but no result...

Doh!

Edited by gertsolo

The more you learn, the less you know.

Share this post


Link to post
Share on other sites
weaponx

According to the M$ knowledgebase, that error means it's not a dll file.

http://support.microsoft.com/kb/249873

Well thats about as smart as keyboard error, press f1 to continue.

Share this post


Link to post
Share on other sites
gertsolo

According to the M$ knowledgebase, that error means it's not a dll file.

http://support.microsoft.com/kb/249873

Well thats about as smart as keyboard error, press f1 to continue.

You're right there, buddy.

So now what?


The more you learn, the less you know.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×