Jump to content
Sign in to follow this  
tinman_72

Displaying an image in GUI is garbled.

Recommended Posts

tinman_72

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

Share this post


Link to post
Share on other sites
tinman_72

I have been struggling with this for hours. After I posted this I tried removing the background color of the GUI. This seems to have fixed the problem. So how can I display an image within a GUI that has a background color defined?

Share this post


Link to post
Share on other sites
genius257

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 :)

Share this post


Link to post
Share on other sites
tinman_72

Thanks. I've looked over GDI+ before and had trouble understanding it. Guess I have some reading to do.

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  

×