Jump to content

Move Image


Go to solution Solved by lokipoki,

Recommended Posts

Hi there.

Here we go again.

I want to move a picture. This is my code

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>



$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUICtrlSetBkColor($hgui, 0x000000)
GUICtrlCreatePic('SNES.jpg', 0, 0, @DesktopWidth, @DesktopHeight)

GUISetState()

_GDIPlus_Startup()
$hcartridge = _GDIPlus_ImageLoadFromFile('D:\HTPC\Games\SNES\Roms\cartridge\Batman Forever (E) [!].jpg')

$iWidth = _GDIPlus_ImageGetWidth($hcartridge)
$iHeight = _GDIPlus_ImageGetHeight($hcartridge)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)


$inc = 0
$x = 625
$y = -75


Do

_GDIPlus_GraphicsDrawImage($hGraphic, $hcartridge, $x, $y)

$y = $y + 1

Sleep(15)

$inc = $inc + 1
Until $inc = 135


 While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

This is the result after I mover the picture from the top. It makes those marks:

https://skydrive.live.com/embed?cid=F6554FE8FA489447&resid=F6554FE8FA489447%21187&authkey=ACAyCLroOvnjYzU

What am I doing wrong? Im pretty sure its simple :)

Edited by lokipoki
Link to comment
Share on other sites

Looks like you need to repaint your background image. You could try using GUICtrlSetImage to redraw it.

A less-likely cause of the problem is the GDI+ image you're moving. It's funny when it comes to repainting. Check out the code here. I put a GDI repainting function at the very bottom. Don't forget to register the function. If the problem is GDI repainting, this should help fix it.

Link to comment
Share on other sites

Looks like you need to repaint your background image. You could try using GUICtrlSetImage to redraw it.

A less-likely cause of the problem is the GDI+ image you're moving. It's funny when it comes to repainting. Check out the code here. I put a GDI repainting function at the very bottom. Don't forget to register the function. If the problem is GDI repainting, this should help fix it.

How do I use GUICtrlSetImage???

Link to comment
Share on other sites

http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm

You need to have a handle to the picture you created.  Try something like:

$hPic = GUICtrlCreatePic('SNES.jpg', 0, 0, @DesktopWidth, @DesktopHeight)

Then you use GUICtrlSetImage to update the picture whenever you need to.  Something like:

GUICtrlSetImage($hPic, 'SNES.jpg')

You'd probably want to have that in your Do..Until loop.

Link to comment
Share on other sites

http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm

You need to have a handle to the picture you created.  Try something like:

$hPic = GUICtrlCreatePic('SNES.jpg', 0, 0, @DesktopWidth, @DesktopHeight)

Then you use GUICtrlSetImage to update the picture whenever you need to.  Something like:

GUICtrlSetImage($hPic, 'SNES.jpg')

You'd probably want to have that in your Do..Until loop.

 

Hi there.

Thanks for your reply. It works indeed.

But my moving picture starts to blink now.

What can I do?

Cheers.

Link to comment
Share on other sites

Without seeing your code, I can't say exactly why it's flashing.  It probably flashes when it gets redrawn.  Make sure you're not calling GUICtrlSetImage more than you need to.  If you're only calling it when you absolutely need to and it's still flashing, you may need to look into using the GDI+ UDF instead.  I'm not an expert on graphics, though, so there may be other options.

Link to comment
Share on other sites

Without seeing your code, I can't say exactly why it's flashing.  It probably flashes when it gets redrawn.  Make sure you're not calling GUICtrlSetImage more than you need to.  If you're only calling it when you absolutely need to and it's still flashing, you may need to look into using the GDI+ UDF instead.  I'm not an expert on graphics, though, so there may be other options.

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>




$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUICtrlSetBkColor($hGUI, 0x000000)
$hbpic = GUICtrlCreatePic('SNES.jpg', 0, 0, @DesktopWidth, @DesktopHeight)

GUISetState()

_GDIPlus_Startup()
$hcartridge = _GDIPlus_ImageLoadFromFile('D:\HTPC\Games\SNES\Roms\cartridge\Batman Forever (E) [!].jpg')

$iWidth = _GDIPlus_ImageGetWidth($hcartridge)
$iHeight = _GDIPlus_ImageGetHeight($hcartridge)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)


$inc = 0
$x = 625
$y = -75


Do
$y = $y + 1
GUICtrlSetImage($hbpic, 'SNES.jpg')
_GDIPlus_GraphicsDrawImage($hGraphic, $hcartridge, $x, $y)
Sleep(15)
$inc = $inc + 1

Until $inc = 135


 While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
Link to comment
Share on other sites

Using GDI+ here isn't needed.  You just want to show & move a picture.  Try something like this:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$x = 625
$y = -75
$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
; GUICtrlSetBkColor($hGUI, 0x000000)  ; Not really needed since the background covers the whole screen
$hbpic = GUICtrlCreatePic(@ScriptDir & '\SNES.bmp', 0, 0, @DesktopWidth, @DesktopHeight)
$hcartridge = GUICtrlCreatePic(@ScriptDir & '\FF3.jpg', $x, $y)
GUISetState()

For $y = -75 To 60
    GUICtrlSetPos($hcartridge, $x, $y)
    Sleep(15)
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Make sure to update the image names, of course.  There's no flicker that I can see with this version. Edited by Artisan
Link to comment
Share on other sites

Using GDI+ here isn't needed.  You just want to show & move a picture.  Try something like this:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$x = 625
$y = -75
$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
; GUICtrlSetBkColor($hGUI, 0x000000)  ; Not really needed since the background covers the whole screen
$hbpic = GUICtrlCreatePic(@ScriptDir & '\SNES.bmp', 0, 0, @DesktopWidth, @DesktopHeight)
$hcartridge = GUICtrlCreatePic(@ScriptDir & '\FF3.jpg', $x, $y)
GUISetState()

For $y = -75 To 60
    GUICtrlSetPos($hcartridge, $x, $y)
    Sleep(15)
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Make sure to update the image names, of course.  There's no flicker that I can see with this version.

 

 

Thanks a lot. The script is working although it still flickers. But not as much as before.

Cheers.

Edited by lokipoki
Link to comment
Share on other sites

Try this:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$x = 625
$y = -75
$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
; GUICtrlSetBkColor($hGUI, 0x000000)  ; Not really needed since the background covers the whole screen
$hbpic = GUICtrlCreatePic(@ScriptDir & '\SNES.bmp', 0, 0, @DesktopWidth, @DesktopHeight)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGUI)
$hGUI_Child = GUICreate('', 420, 340, @DesktopWidth / 2 - 210, - 75, $WS_POPUP, Default, $hGUI)
$hcartridge = GUICtrlCreatePic(@ScriptDir & '\FF3.jpg', 0, 0, 420, 340)
GUISetState(@SW_SHOW, $hGUI_Child)

For $y = -75 To 160
    WinMove($hGUI_Child, "", @DesktopWidth / 2 - 210, $y)
    Sleep(15)
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Br,

UEZ

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Solution

Try this:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$x = 625
$y = -75
$hGUI = GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
; GUICtrlSetBkColor($hGUI, 0x000000)  ; Not really needed since the background covers the whole screen
$hbpic = GUICtrlCreatePic(@ScriptDir & '\SNES.bmp', 0, 0, @DesktopWidth, @DesktopHeight)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW, $hGUI)
$hGUI_Child = GUICreate('', 420, 340, @DesktopWidth / 2 - 210, - 75, $WS_POPUP, Default, $hGUI)
$hcartridge = GUICtrlCreatePic(@ScriptDir & '\FF3.jpg', 0, 0, 420, 340)
GUISetState(@SW_SHOW, $hGUI_Child)

For $y = -75 To 160
    WinMove($hGUI_Child, "", @DesktopWidth / 2 - 210, $y)
    Sleep(15)
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Br,

UEZ

 

 

Thanks mate.

Its working perfectly!!!

Thanks for all your help guys.

Cheers.

 

Edited by lokipoki
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...