Moist Posted October 18, 2018 Share Posted October 18, 2018 Hello guys, I've seen people having trouble with adding .png images to GUI, but were able to add .bmp image. Well, I can't seem to add anything. Here's an example: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("", 300, 300, 500, 500) $Pic = GUICtrlCreatePic(@ScriptDir&"\1.bmp", 10, 10, 50, 45) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE EndSwitch WEnd The GUI appears, but there is no image. Link to comment Share on other sites More sharing options...
Andreik Posted October 18, 2018 Share Posted October 18, 2018 (edited) Script is fine, just make sure your bitmap is where is suppose to be, in the right location. Maybe adding this line to check the file before would help you. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> If Not FileExists(@ScriptDir&"\1.bmp") Then MsgBox(0,'','File not exists!') GUICreate("", 300, 300, 500, 500) $Pic = GUICtrlCreatePic(@ScriptDir&"\1.bmp", 10, 10, 50, 45) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited October 18, 2018 by Andreik Link to comment Share on other sites More sharing options...
Moist Posted October 18, 2018 Author Share Posted October 18, 2018 I've added that to my script, but no warning. The file is indeed in my script's folder. Is there any requirements for the image used? Link to comment Share on other sites More sharing options...
Andreik Posted October 18, 2018 Share Posted October 18, 2018 No special requirements are needed. Can you upload your bitmap for a test? Link to comment Share on other sites More sharing options...
Moist Posted October 18, 2018 Author Share Posted October 18, 2018 I was never able to use any bitmap image. But here is the one that I was trying to add now. Maybe something wrong with my computer? 1.bmp Link to comment Share on other sites More sharing options...
Subz Posted October 18, 2018 Share Posted October 18, 2018 Couldn't get it working either, however I just opened your 1.bmp with Paint and then saved it again as 1.bmp and it worked fine after that so something wrong with the original bmp. Moist 1 Link to comment Share on other sites More sharing options...
Andreik Posted October 18, 2018 Share Posted October 18, 2018 (edited) Your bitmap has BITMAPV5HEADER and this seems to be unsupported by these functions. Something like this might be a workaround. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> GUICreate("", 300, 300) $Pic = GUICtrlCreatePic('', 10, 10, 50, 45) SetBitmapToCtrl(@ScriptDir & '\1.bmp', $Pic) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func SetBitmapToCtrl($sPath, $iCtrl) _GDIPlus_Startup() $hPic = _GDIPlus_BitmapCreateFromFile($sPath) $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPic) _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl,0x0172,0,$hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_BitmapDispose($hPic) _GDIPlus_Shutdown() EndFunc Edited October 18, 2018 by Andreik Link to comment Share on other sites More sharing options...
Moist Posted October 18, 2018 Author Share Posted October 18, 2018 1 hour ago, Subz said: Couldn't get it working either, however I just opened your 1.bmp with Paint and then saved it again as 1.bmp and it worked fine after that so something wrong with the original bmp. Thanks, that solved it for me. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now