Jump to content

Display bitmap from memory without GDI+?


qwert
 Share

Recommended Posts

I've been using GDI+ to display bitmap images directly from memory as shown in several examples on this forum.  Here's a snippet of the method:

Global $image = "0x89504E470D0A1A0A0000000D49 ... etc.  ; hex value of image to display

_GDIPlus_Startup()  
$iPic = GUICtrlCreatePic("", 100, 50, 20, 20)
$hPic = GUICtrlGetHandle($iPic)
$hHBitmap = _GDIPlus_BitmapCreateFromMemory(Binary($image), True)
_WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, 0, $hHBitmap))
_GDIPlus_Shutdown()

But I have a case where I only want to place a single small bitmap on a GUI.  Starting and stopping GDI+ seems like a lot of overhead when the bitmap already exists in a variable.

Is there a way to display a bitmap from memory without using GDI+?

Thanks in advance for any help.

 

 

Link to comment
Share on other sites

What do you mean with overhead? I don't see a overhead here.

 

Put _GDIPlus_Startup() at the top of your script and when exiting just _GDIPlus_Shutdown. 2 calls is not an overhead.

Edited by UEZ

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

Link to comment
Share on other sites

By "overhead", I mean 1) added size to the compiled script size and 2) additional execution time at run time.

Are you saying that there's no "cost" in CPU time of starting and stopping GDI+?  Is it truly negligible?

Link to comment
Share on other sites

is there any difference (size, speed) when you do it with resources? I imagine most every solution is going to take a hit somewhere, but i would be interested if you see any noticeable differences 

#AutoIt3Wrapper_Res_File_Add="C:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg" , rt_rcdata, TEST_JPG_1
#include<resources.au3>

$gui = GUICreate("Data from resources simple example 1",400,150)
$pic1 = GUICtrlCreatePic("",0,0,400,150)
_ResourceSetImageToCtrl($pic1, "TEST_JPG_1") ; set JPG image to picture control from resource
GUISetState(@SW_SHOW)

While 1
 If GUIGetMsg() = -3 Then Exit
WEnd

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

boththose, I see what you're suggesting.  But in Resources.au3 I see:

Func _SetBitmapToCtrl($CtrlId, $hBitmap)

Since I already have the bitmap in the form of:

$image = "0x89504E470D0A1A0A0000000D49 ... etc.  ; hex value of image to display

... shouldn't I be able to directly place it with that call?  (not that I see how at this moment!)

And, yes, I'll attempt to measure whatever I come up with against the GDI+ method.

Link to comment
Share on other sites

Since I already have the bitmap in the form of:

$image = "0x89504E470D0A1A0A0000000D49 ... etc.  ; hex value of image to display

... shouldn't I be able to directly place it with that call?

 

 

I could be up to 100% wrong with this answer,

 

but to use resources for this I think you would have to

 

1) #AutoIt3Wrapper_Run_Before and echo that text back to an output file

2) #AutoIt3Wrapper_Res_File_Add that output file  as ResourceSetImageToCtrl requires the name you set in this directive.

 

GDI is looking pretty sweet.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

By "overhead", I mean 1) added size to the compiled script size and 2) additional execution time at run time.

Are you saying that there's no "cost" in CPU time of starting and stopping GDI+?  Is it truly negligible?

 

Each function runs in a few milliseconds! Loading the encoded image takes some more milliseconds. Normally your are loading the image once only, not permanently!

About the size:, if you are using binary strings within your script the compiled exe size is larger than adding the image as resources to your script.

You can use both variants for your scripts. I personally use only the binary encoded strings within my scripts.

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

Link to comment
Share on other sites

Thanks to you both.

I think you've given me what I need to explore each alternative.  Maybe then I can take a shot at a minimal version of _SendImage that I can embed.

_SendMessage($hPic, $STM_SETIMAGE, 0, $hHBitmap)

Regarding script size, I'm most concerned about the footprint of the script when it's running.  The particular one I'm working on could have several copies active at the same time ... so I don't want basic inefficiencies to adding.  (Ideally, they would share some structure that contained common resources, but I'm not technically ready to explore that at this point.  Everything needs to be working first.)

 

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