Sign in to follow this  
Followers 0
silverhawk1842

GUICreateCtrlPic not working consistantly

9 posts in this topic

Below is a snippit of my code,

;---begin pre script excerpt
#include <file.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

$phone='a'
$title='0'

;---end pre script excerpt

    $files=_FileListToArray(@ScriptDir&'\output\'&$phone&'\',$title&'*.jpg',1)
            
    _GDIPlus_Startup()
    $win2=GUICreate("cropper")
    $win2bg = GUICtrlCreatePic('',0,0,1,1,$win2)
    $cropbar=GUICtrlCreatePic(@ScriptDir&'\res\cropbar.gif',0,0,200,1,$win2)
    ;GUISwitch($GUI)
    
    for $i=1 to $files[0]
        if $i<4 then
            ;GUICtrlSetData($status,"cropping top of thumbnail")
            $img=_GDIPlus_ImageLoadFromFile(@ScriptDir&'\output\'&$phone&'\'&$files[$i])
            $w=_GDIPlus_ImageGetWidth($img)/10
            $h=_GDIPlus_ImageGetHeight($img)/10
            _GDIPlus_ImageDispose($img)
            ;msgbox(0,FileExists(@ScriptDir&'\output\'&$phone&'\'&$files[$i]),@ScriptDir&'\output\'&$phone&'\'&$files[$i])
            winmove($win2,default,default,$w,$h)
            GUISetState(@SW_SHOW,$win2)
            GUICtrlSetPos($cropbar,0,0,$w,1)
            GUICtrlSetPos($win2bg,0,0,$w,$h)
            GUICtrlSetImage($win2bg,@ScriptDir&'\output\'&$phone&'\'&$files[$i])
            $show=1
            While $show<>0
                $msg = GUIGetMsg($win2)
                Select
                    Case $msg = $GUI_EVENT_MOUSEMOVE
                        $a=GUIGetCursorInfo($win2)
                        GUICtrlSetPos($cropbar,0,$a[1])
                    case $msg = $GUI_EVENT_PRIMARYDOWN
                        $a=GUIGetCursorInfo($win2)
                        $croppos=$a[1]*10
                        GUISetState(@SW_HIDE,$win2)
                        $show=2
                    case $msg = $GUI_EVENT_PRIMARYUP
                        if $show=2 then $show=0
                        Exit
                EndSelect
            WEnd
            
        EndIf
    Next

Here are the possible outcomes: (of only close and reopen)

1

2

3

4 //close to the desired output

5

6

7

8

9

10

here are my resource images

/res/cropbar.gif

and

/output/a/00.jpg

The basis for my script is to display a dialogue, showing a scaled down thumbnail of an image to be cropped. the red cropbar indicates the position to be cropped.

It has worked perfectly about 2 times (like the image indicated, but without a border on cropbar)

the image comes from an image magic script and then goes back to imagemagic for processing, i have no problem with this.

Please tell me what is going wrong.

Win XP Pro sp3

Autoit version: 3,3,6,1

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

defining the outcomes

1 no cropbar

2 no images & nothing resizing

3 no images, but with resizing

4 close to the desired output but there is a border on the cropbar

5 no images, but with some resizing

6 bad image

7 no images, with some resizing, i dont know what cropbar is doing

8 1 image loaded

9 no images with scrollbars

10 both images, scrollbars, and fat cropbar

11 i dont know hat is going on!

12 some wierd blue thing on top

Edited by silverhawk1842

Share this post


Link to post
Share on other sites

silverhawk1842,

Welcome to the AutoIt forum. :)

I found a few syntax errors scattered through the script (look for <<<<<<<<<< lines) and I changed your .gif image into a .jpg - I have never had much luck with .gifs in a Pic control. :P

This seems to work for me - I altered the size as your base image was far to small to make a sensible GUI if reduced by a factor of 10:

;---begin pre script excerpt
#include <file.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

$phone = 'a'
$title = '0'

;---end pre script excerpt

$files = _FileListToArray(@ScriptDir & '\', $title & '*.jpg', 1)

_GDIPlus_Startup()
$win2 = GUICreate("cropper")
$win2bg = GUICtrlCreatePic('', 0, 0, 1, 1);, $win2) ; syntax <<<<<<<<<<<<<<<<  Why GUI handle ?
$cropbar = GUICtrlCreatePic(@ScriptDir & '\cropbar.jpg', 0, 0, 200, 1);, $win2) ; syntax <<<<<<<<<  Why GUI handle ?

;GUISwitch($GUI)

For $i = 1 To $files[0]
    If $i < 4 Then
        ;GUICtrlSetData($status,"cropping top of thumbnail")
        $img = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\' & $files[$i])
        $w = Ceiling(_GDIPlus_ImageGetWidth($img) / 2)
        $h = Ceiling(_GDIPlus_ImageGetHeight($img) / 2)
        _GDIPlus_ImageDispose($img)

        WinMove($win2, "", Default, Default, $w, $h) ; syntax <<<<<<<<<<<<<<<<<<< added "" for "text" parameter
        GUICtrlSetPos($cropbar, 0, 0, $w, 1)
        GUICtrlSetPos($win2bg, 0, 0, $w, $h)
        GUICtrlSetImage($win2bg, @ScriptDir & '\' & $files[$i])

        GUISetState()

        $show = 1
        While $show <> 0

            $msg = GUIGetMsg() ; syntax <<<<<<<<<<<<<<<<<<<<<  Why GUI handle?
            Select
                Case $msg = $GUI_EVENT_MOUSEMOVE
                    $a = GUIGetCursorInfo($win2)
                    GUICtrlSetPos($cropbar, 0, $a[1])
                Case $msg = $GUI_EVENT_PRIMARYDOWN
                    $a = GUIGetCursorInfo($win2)
                    $croppos = $a[1] * 10
                    GUISetState(@SW_HIDE, $win2)
                    $show = 2
                Case $msg = $GUI_EVENT_PRIMARYUP
                    If $show = 2 Then $show = 0
                    Exit
            EndSelect
        WEnd

    EndIf
Next

Does it work for you now? Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you for helping,

I used the GUI Handle because I have 2 GUIs and call GUISwitch($win1) shortly after initiating $win2.

Anyway, I changed the cropbar.gif to a jpg and added the quotes for winmove, and I am still getting the random issues.

The jpeg dimensions are normally

1700x2200

1175x850

1461x969

1750x2300

...

divided by 2 is still too big to get the jest of the image.

do you think they are too big for autoit?

Edited by silverhawk1842

Share this post


Link to post
Share on other sites

silverhawk1842,

I used the GUI Handle because...

But in none of those cases is the GUI handle required by AutoIt - go and look in the Help file. You are putting the random GUI handle value into the "style" parameter of the Pic controls which is quite possibly the reason for the errors you are getting. And the only parameter you can use with GUIGetMsg is a simple "1"! :)

do you think they are too big for autoit?

Certainly not if you are factoring them. Perhaps you could adjust your factoring to get a roughly "standard" size so you do not have wildly differing reduction values.

I am still getting the random issues

Do these occur when different images are displayed? What happens if you use just the one image and run the loop several times using only that image? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks,

That makes sense. The GUIHandle is a semi-random integer, thus, assigning the controls a random (and sometimes non-existent) style. This was the reason for all the odd outcomes.

I feel stupid.

Edited by silverhawk1842

Share this post


Link to post
Share on other sites

silverhawk1842,

I take it that all is now well? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

We are good, Thanks!

Share this post


Link to post
Share on other sites

I found a bug, or at least something that needs to be mentioned somewhere.

Autoit cannot display images in CMYK colorspace, if you are having problems when you try to load an image and are getting "0" returned, convert your image to RGB colorspace.

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  
Followers 0