Jump to content

Displaying an image in GUI is garbled.


tinman_72
 Share

Recommended Posts

I have a GUI which I am using GUICtrlCreatePic to display a JPEG. For some reason in the GUI it is garbled but all programs I open it with show it properly. I have tried converting it to a bitmap with the same issue.  The code I am using is pretty straight forward:

Local $hGUIChoose = GUICreate ( "Title", 400, 250 )
    GUISetBkColor ( 0x004e99, $hGUIChoose )
GUICtrlCreateLabel ( "Some text", 10, 10, 380 )
    GUICtrlSetFont ( -1, 10, 600, 0, "", 5 )
    GUICtrlSetColor ( -1, 0x80c0ff )
GUICtrlCreatePic ( @TempDir & "\click_here.bmp", 81, 80, 0, 0 )

I have included a snapshot of the GUI with the garbled image next to the file displayed in Window's viewer. I have also attached a copy of the source JPEG. Any insight would be very much appreciated.

why.png

click_here.jpg

Link to comment
Share on other sites

Hi @tinman_72.

My suggestion, is to use GDI+

I'm sure there is a way to make it work the other way, but this was quicker for me ;)

#include <GDIPlus.au3>

Opt("GuiOnEventMode", 1)

_GDIPlus_Startup()
$hBitmap = _GDIPlus_ImageLoadFromFile("click_here.jpg")

GUIRegisterMsg(0x000F, "WM_PAINT")

Local $hGUIChoose = GUICreate ( "Title", 400, 250 )
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUIChoose)
GUISetState()
    GUISetBkColor ( 0x004e99, $hGUIChoose )
GUICtrlCreateLabel ( "Some text", 10, 10, 380 )
    GUICtrlSetFont ( -1, 10, 600, 0, "", 5 )
    GUICtrlSetColor ( -1, 0x80c0ff )

OnAutoItExitRegister("CleanUp")
GUISetOnEvent(-3, "MyExit", $hGUIChoose)

While 1
    Sleep(10)
WEnd

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 81, 80, 238, 157)
EndFunc

Func CleanUp()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc

Func MyExit()
    Exit
EndFunc

Hope this helps :)

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...