Rex

Set img to button from base64 or binary

7 posts in this topic

Hi

I have been searching for a way to set img to buttons from either Base64 or Binary code

I found this thread https://www.autoitscript.com/forum/topic/129550-set-binary-png-image-to-button-ctrl/ but I can't get it to work.

My problem is that I needed some large checkboxes, but it seems that size of std chackboxes can't be changed, so I created 2 images one with check on and one blank.

Those I have set to buttons and uses them as checkboxes instead, course I needed on event management for em, and also wanted to be able to tab to them, like normal checkboxes.

I know that I could use the ResurcesEx UDF to emp the img's to the exe file, but then the img's only would work when compiled.

Is there some way to use button images from either Binary or Base64 code, directly from the script? Or would it be a bad idea to do so?

 

My code is quit simple for the check part

Func idBtn_Chk1()
If GuiCtrlRead($idBtn_Chk1) = 1 then
GuiCtrlSetData($idBtn_Chk1, 0)
GUICtrlSetImage($idBtn_Chk1, $dIconOn, -1, 0)
$g_bChk1 = True
Else
GuiCtrlSetData($idBtn_Chk1, 1)
GUICtrlSetImage($idBtn_Chk1, $dIconOff, -1, 0)
$g_bChk1 = False
Endif
Endfunc

 

Any suggestions, to do it another and more simple way is of course welcome :)

 

Cheers
/Rex

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Creating Bitmap from memory is a good idea if you don't want that user can change a bitmap. Otherwise creating Bitmap from a file is easier if changing of bitmap may be needed in future.

Here a small example creating a piccontrol with a bitmap from mem:

;coded by UEZ 2011
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#Include <Memory.au3>

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global $msg
Global Const $hBmp = _GDIPlus_BitmapCreateFromMemory(InetRead("https://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.png"), True) ;to load an image from the net
Global Const $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
Global Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
Global Const $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
Global Const $hGUI = GUICreate("Display PNG Image in picture control", $iWidth, $iHeight)
Global Const $idPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp))
GUISetState()

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case $idPic
            MsgBox(0, "Information", "PNG image was clicked"&@crlf&@crlf&"found: https://www.autoitscript.com/forum/topic/144934-guictrlsetimage-does-not-always-draw-picture/?do=findComment&comment=1023152")
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hBmp)
            _GDIPlus_BitmapDispose($hBitmap)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            Exit
    EndSwitch
WEnd

Edit: changed to _GDIPlus_BitmapCreateFromMemory.

Edited by AutoBert

Share this post


Link to post
Share on other sites

Checkout 

The example above are obsolete because Load_BMP_From_Mem is already integrated -> _GDIPlus_BitmapCreateFromMemory()


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

Share this post


Link to post
Share on other sites

@AutoBert

The user should not be able to change the bitmap.

I have already tried the exp posted, couldn't get it to work ether :(

@UEZ

I use your Base64 converter quit often :P it's a good like tool :wub:

But I couldn't get it to work correctly for my project, I guess it's be corse I put it in a function that I then calls when the user clicks the button (checkbox), one for on and one for off, currently I have 10 buttons, that is in use as checkboxes.

 

Cheers
/Rex

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't know where your problems are here the example with hardcoded png: loadBmpFromMem.au3

Edited by AutoBert

Share this post


Link to post
Share on other sites
4 minutes ago, AutoBert said:

I don't know where your problems are here the example with hardcoded png: loadBmpFromMem.au3

I couldn't get it work for a button control, I have no problem using it with a piccontrol - that I do in other of my programs

Cheers
/Rex

Share this post


Link to post
Share on other sites

I found out why I couldn't get it to work.

I did send the guictrlID to the function and not the handle as I should had :> Sry (using UEZ's base64 example)

 

Cheers
/Rex

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