Jump to content
Sign in to follow this  
pixelsearch

Display png images

Recommended Posts

Hi everybody :)
I would like to thank UEZ  for the great help he brought us concerning what follows :
When I right click a row in the following ListView, the corresponding image should be displayed in a Splash Window and disappear as soon as the mouse moves. But as you can see below, nothing happens when the image is .png type (as stated in the help file, topics SplashImageOn and GUICtrlCreatePic)

783726549_pngnotvisiblewithSplashImage.png.d852e40e07fdd4de20635b762e749202.png

Now see how it works fine with jpg, gif or bmp :

1909198249_jpgvisiblewithSplashImage.jpg.63d860b4340509401ab1c924b3d658bf.jpg

Gladly UEZ indicated not 1, but 2 different ways to solve this, allowing us to display png files using GDI+
 Let's start with way #1, simulating a Splash Window :

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

$sFileName = @ScriptDir & "\Torus.png"
If Not FileExists($sFileName) Then _
    Exit MsgBox($MB_TOPMOST, "Error", $sFileName & " not found")

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)

$hGUI = GUICreate("", $iX, $iY, -1, -1, _
    $WS_BORDER + $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)

$aPos_Old = MouseGetPos()
Do
    $aPos_New = MouseGetPos()
    Sleep(100)
Until $aPos_Old[0] <> $aPos_New[0] Or $aPos_Old[1] <> $aPos_New[1]

GUIDelete($hGUI)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Now the 2nd way, displaying the png image in a GUI picture control :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

$sFileName = @ScriptDir & "\Torus.png"
If Not FileExists($sFileName) Then _
    Exit MsgBox($MB_TOPMOST, "Error", $sFileName & " not found")

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

$hGUI = GUICreate("Display PNG Image in picture control", $iX, $iY, -1, -1, _
    -1, $WS_EX_TOPMOST)
$idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY)
GUICtrlSendMsg($idPic, 0x0172, 0, $hBitmap) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            _WinAPI_DeleteObject($hBitmap)
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            Exit

        Case $idPic
            MsgBox($MB_TOPMOST, "Information", "PNG image was clicked")
    EndSwitch
WEnd

The "Torus.png" image can be downloaded just below in case you want to try the scripts. Just rename it "Torus.png" and place it in the same folder than the scripts.

@UEZ : :thumbsup:  and let's hope this will be useful for those who encountered the same issue.

@Mods : I didn't know where to post this comment. If you think it should be placed in another part of the Forum, please be kind enough to move it there, thanks.

Torus.png

 

Edited by pixelsearch

Share this post


Link to post
Share on other sites
Quote

 I didn't know where to post this comment. I

The "Snippets" thread perhaps ?

 


Some guy's script + some other guy's script = my script!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...