Blinking image

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Blinking image

14 Dec 2017, 03:48

I have created a very simple script in which a jpg image changes depending on the position of the cursor.
It is basically a loop that includes:

Code: Select all

GuiControl, , Imagen, C:\Folder\Subfolder\Project\Picture%Angle%.jpg
where Angle takes values 1, 2, 3, etc. depending on the cursor position.

My problem is that although it is a very light script (827Kb the .exe) the image blinks a lot, even when not running any other program.

Is there any easy way to avoid this?
Maybe through stablishing something like a preference or so, memory or so?

Thanks a lot.
Desiet

Re: Blinking image

14 Dec 2017, 04:45

Diego wrote:I have created a very simple script in which a jpg image changes depending on the position of the cursor.
It is basically a loop that includes:

Code: Select all

GuiControl, , Imagen, C:\Folder\Subfolder\Project\Picture%Angle%.jpg
where Angle takes values 1, 2, 3, etc. depending on the cursor position.

My problem is that although it is a very light script (827Kb the .exe) the image blinks a lot, even when not running any other program.

Is there any easy way to avoid this?
Maybe through stablishing something like a preference or so, memory or so?

Thanks a lot.
hard to tell without you providing the code

many things you can try but it depends on current code (things like loading all images on gui show (hidden), png transparent and so on)
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Blinking image

14 Dec 2017, 04:56

You could try the code given in the helpfile as demo for loadpicture , i would use gdip to display changing images but it has a learning curve .....
https://autohotkey.com/docs/commands/LoadPicture.htm

for a gdip example see BlackHolyMan 's code : https://autohotkey.com/board/topic/9018 ... i-add-pic/

helpfile example loadpicture:

Code: Select all

; Pre-load and reuse some images.

Pics := []
; Find some pictures to display.
Loop, Files, %A_WinDir%\Web\Wallpaper\*.jpg, R
{
    ; Load each picture and add it to the array.
    Pics.Push(LoadPicture(A_LoopFileFullPath))
}
if !Pics.Length()
{
    ; If this happens, edit the path on the Loop line above.
    MsgBox, No pictures found!  Try a different directory.
    ExitApp
}
; Add the picture control, preserving the aspect ratio of the first picture.
Gui, Add, Pic, w600 h-1 vPic +Border, % "HBITMAP:*" Pics.1
Gui, Show
Loop 
{
    ; Switch pictures!
    GuiControl, , Pic, % "HBITMAP:*" Pics[Mod(A_Index, Pics.Length())+1]
    Sleep 3000
}
return
GuiClose:
GuiEscape:
ExitApp
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Re: Blinking image

14 Dec 2017, 05:04

I´ll try that.
Thanks so much for your help.
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Re: Blinking image

14 Dec 2017, 07:51

hard to tell without you providing the code
You are very right.
Here is the code:

Code: Select all

#SingleInstance, Force
#NoEnv
#Persistent

Gui -Caption
Gui, +AlwaysOnTop +ToolWindow -SysMenu
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImagen,
Gui, Show, w%Tamaño% h%Tamaño%, Fisgón

CoordMode, Mouse, Screen

loop
{	
	; Some if/else commands that modify the value of variable Sec depending on mouse position.
		
	GuiControl, , Imagen, C:\Folder\Subfolder\AutoHotKeys\Projects\Picture%Sec%.jpg	
	Gui, Submit, NoHide
}
Return
	
GuiClose:
	ExitApp
	Return	
many things you can try but it depends on current code (things like loading all images on gui show (hidden), png transparent and so on)
Could you please elaborate a bit about the first option (about the "gui show (hidden)")?
The images are 36 normal pictures in jpg.

Thanks a lot.
Desiet

Re: Blinking image

14 Dec 2017, 08:00

Try having all the images load when the gui launches but hide them

Code: Select all

Gui -Caption
Gui, +AlwaysOnTop +ToolWindow -SysMenu
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImagen,
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImg1, img1.png
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImg2, img2.png
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImg3, img3.png
Gui, Add, Picture, x0 y0 w%Tamaño% h%Tamaño% vImg4, img4.png
guicontrol, hide, Img1
guicontrol, hide, Img2
guicontrol, hide, Img3
guicontrol, hide, Img4

Gui, Show, w%Tamaño% h%Tamaño%, Fisgón
then later on when you want to show it just say

guicontrol, show, img1

see if it helps, it usually does and programs are like websites, preload as much as possible when it comes to graphic elements, and tell those who tell you about saving memory and resources that its not 2001 anymore, 36 photos are nothing
Diego
Posts: 10
Joined: 12 Dec 2017, 05:14

Re: Blinking image

14 Dec 2017, 08:49

Fantastic. I´ll try that.

I guess for showing them I have to put the "Sec" variable (the one that changes with the mouse position) in GuiControl, Show:

Code: Select all

GuiControl, Show, img%Sec%
I´m planning to have 72 pictures (36 was just for testing, but not the real thing), each with a weight of more or less 20KB.

I guess I could do a "for-loop" or "while-loop" for loading all the images in one go (I still have to learn those things, but I am sure it will be possible).
In this way, if in the future I modify the number of images I would have to change just one variable.

Many thanks again for your great help! :superhappy: :superhappy:
Desiet

Re: Blinking image

14 Dec 2017, 10:35

Diego wrote:Fantastic. I´ll try that.

I guess for showing them I have to put the "Sec" variable (the one that changes with the mouse position) in GuiControl, Show:

Code: Select all

GuiControl, Show, img%Sec%
I´m planning to have 72 pictures (36 was just for testing, but not the real thing), each with a weight of more or less 20KB.

I guess I could do a "for-loop" or "while-loop" for loading all the images in one go (I still have to learn those things, but I am sure it will be possible).
In this way, if in the future I modify the number of images I would have to change just one variable.

Many thanks again for your great help! :superhappy: :superhappy:
I would load it normal and just display a 5 second progress bar

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ArkuS, mikeyww, Nerafius, sofista and 113 guests