wraithdu

Problem with GUICtrlCreatePic / GUICtrlSetImage

8 posts in this topic

Does anyone else think this is a bug? The example is self explanatory.

#include <ScreenCapture.au3>

$file = @DesktopDir & "\capture.jpg"
$file2 = @DesktopDir & "\capture2.jpg"
_ScreenCapture_Capture($file, 0, 0, 640, 480)
_ScreenCapture_Capture($file2, 400, 0, 1040, 480)

GUICreate("", 400, 300)
$pic = GUICtrlCreatePic($file, 10, 40, 320, 240)
$status = GUICtrlCreateLabel("The original 640x480 image fit to 320x240...", 10, 10, 380)
GUISetState()

Sleep(3000)
GUICtrlSetData($status, "Change the image, still 320x240...")
GUICtrlSetImage($pic, $file2)
Sleep(3000)
GUICtrlSetData($status, "Blank the control via GUICtrlSetImage($pic, """")...")
GUICtrlSetImage($pic, "")
Sleep(3000)
GUICtrlSetData($status, "Set the image again, but now the control forgot its size.")
GUICtrlSetImage($pic, $file)
Sleep(3000)

FileDelete($file)
FileDelete($file2)

Share this post


Link to post
Share on other sites



I don't know whether this is a bug or a feature but after GUICtrlSetImage($pic, "") the settings for $pic will be reset.

One workaround:

...


GUICtrlSetImage($pic, "")
Sleep(3000)
GUICtrlSetData($status, "Set the image again, but now the control forgot its size.")
$pic = GUICtrlCreatePic($file, 10, 40, 320, 240) ;workaround is to set $pic again
GUICtrlSetImage($pic, $file)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Except that duplicates the control. You'd have to do a GUICtrlDelete($pic) as well. I've already considered the workarounds. In the app where I first ran into this, I just created a transparent png that I used instead of GUICtrlSetImage($pic, "").

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I use GUICtrlSetPos() after GUICtrlSetImage($Pic, "").

I just tried that, didn't work, which was surprising.

GUICtrlSetData($status, "Blank the control via GUICtrlSetImage($pic, """")...")
GUICtrlSetImage($pic, "")
GUICtrlSetPos($pic, 10, 40, 320, 240)
Sleep(3000)
GUICtrlSetData($status, "Set the image again, but now the control forgot its size.")
GUICtrlSetImage($pic, $file)
Sleep(3000)
Edited by wraithdu

Share this post


Link to post
Share on other sites

Back from the holiday now...

So, I don't see a consensus here... is this a bug? If so I'll report it. Maybe not a bug but a designed behavior that might be changed (= feature req)?

Share this post


Link to post
Share on other sites
Hello everyone!
The theme is very old, but still is not fixed. After properly remove and re-create a permanent control only in order to clean it from the image.
Prompt, who knows what there is more correct solutions to the following example:
GUICtrlSetImage ($PicPreview, "")
GUICtrlSetPos ($PicPreview, 352, 140, 417, 400) ; - this line does not helps!
GUICtrlSetStyle ($PicPreview, $WS_BORDER)

Thanks!

Share this post


Link to post
Share on other sites

I know this actually... by design when you use the set image function whether it be setting an image from a multi image library or a single image file it uses the height and width parameters from the size of the first file it finds for the image size as a separate paramater to the control size for supporting controls that don't initially have an image with a defined size for an image within them like listviewitems etc... so when you blank the image it resets to not having a image size parameter in the control because it no longer has an image and the next time you load the picture it gets the full image size from the file and uses it.

there isnt much you can do about it but you've got the delete the control option already plus you could use the following...

set a transparent colour and load a dummy rectangle image which is just all that transparent colour to keep the size in play on the control but i think just deleting the control and recreating it is probably a better option so you don't have to include an image in the script.

or guictrlsetpos will work if you use it after putting the image back in, not after blanking the control, as the following;

GUICtrlSetImage($pic, "")
Sleep(3000)
GUICtrlSetImage($pic, $file)
GUICtrlSetPos ($Pic, 10, 40, 320, 240)

you can use a flag to make the size resetting conditional if you know when the control is going to be empty;

$flagnone = 0

; other code

GUICtrlSetImage($pic, "")
$flagnone = 1
Sleep(3000)
GUICtrlSetImage($pic, $file)
If $flagnone Then
    GUICtrlSetPos($Pic, 10, 40, 320, 240)
    $flagnone = 0
EndIf

you can also do something like this,

if fileexists($filex) then GUICtrlSetImage($pic, $filex)

or;

if filegetsize($filex) > 0 then GUICtrlSetImage($pic, $filex)

to just not edit it if you dont know when the file is going to be empty or nonexistent

or you can check the control before you update it by using;

$Gui = GuiCreate("Test Gui",400,300)

; other code

$controlpos = ControlGetPos($Gui, "", $pic)
If IsArray($controlpos) Then
    If $controlpos[2] <> 320 Or $controlpos[3] <> 240 Then $flagnone = 1
EndIf

GUICtrlSetImage($pic, $file)
If $flagnone Then
    GUICtrlSetPos($Pic, 10, 40, 320, 240)
    $flagnone = 0
EndIf

unfortunately if you use ControlGetPos you still need to do it after the point the control blanks and set the flag not after trying to put the image back in because the control still has its own size of 320x240 defined and will return that if there is an image of any size at all within it.

surely that explains it...

 

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