Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Image2Include - #include images in your scripts


  • Please log in to reply
18 replies to this topic
just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

Update on 2013-06-02:

  1. Added support for icons; the function will return a HICON handle if required. (THX: tmplinshi)
  2. Changed include script's and function's name from CreateBitmap_name_ext to Create_name_ext.

 

Update on 2013-05-18:

  1. Fixed bug producing invalid function names. All non-word characters (others than "a-z", "A-Z", "0-9", and "_") are stripped from the filename before bulding the script and function name (THX: tmplinshi)
  2. Changed GUI not allowing free typing of file and folder names any more.

 

 

This script is just a simple wrapper for SKAN's How to convert Image data (JPEG/PNG/GIF) to hBITMAP ?. It provides a simple GUI to select images and create #include files for them containing the Base64 encryptet image data and SKAN's code to create a bitmap out of the data.

 

For an image named Test.jpg the script will be named CreateBitmap_Test_jpg.ahk and will contain just one function called CreateBitmap_Test_jpg(). This function creates the bitmap and returns a HBITMAP handle. By default the bitmap is created only once and subsequent calls will return the same handle. This can be changed by passing True as the optional parameter NewHandle.

 

The GUI has only one option which you may choose if you want the bitmap to be created at load-time.

 

I know that several included scripts will contain some redundant code, but I don't care about this waste of memory.

 

It's a good idea to resize the images to the dimensions you need before you create the #include script. And, don't be sad if you try to use an uncompressed image of 2540x1600 pixels with 32 bit color-depth.

 

So here it is:

Spoiler

If it has been done before, I actually missed that.


Prefer ahkscript.org for the time being.


oldbrother
  • Members
  • 149 posts
  • Last active: Nov 09 2014 07:36 PM
  • Joined: 06 Jul 2005

It looks great!



tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012
Great! I like this.
 
I found a small bug, that when the filename contains "-" character, as the function name can't contains '-' character.
 
-------------------------
 
I try to use Image2Include and ILButton() together, I Modified 1 line in ILButton():

 

if (ext = "bmp") {
;hbmp := DllCall("LoadImage", "UInt",0, "Str",v1, "UInt",0, "UInt",cx, "UInt",cy, "UInt",0x10, "UPtr")        ; I comment this line, and added next two lines.
StringReplace, name, A_LoopField, ., _, a
hbmp := CreateBitmap_%name%()

But there is a problem, that the button will restore to standerd style when clicked.
 
Thank you.

just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

I found a small bug, that when the filename contains "-" character, as the function name can't contains '-' character.

Thanks for reporting, it will be fixed.

 


But there is a problem, that the button will restore to standerd style when clicked.

How many pictures do you pass? Does the size of the image fit the cx / cy values you pass to IL_Button()?


Prefer ahkscript.org for the time being.


tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

For example:


ILButton(hBtn, "win_config_n.bmp|win_config_a.bmp|win_config_c.bmp|win_config_n.bmp|win_config_n.bmp|win_config_n.bmp", 27, 17, "", "-3")

The cx / cy is the same as image size.

 

The script Includes 27 images, so I uploaded to here: http://tmplinshi.bin...ahk/SkinGUI2.7z



just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
if (ext = "bmp") {
   ;hbmp := DllCall("LoadImage", "UInt",0, "Str",v1, "UInt",0, "UInt",cx, "UInt",cy, "UInt",0x10, "UPtr") ; I comment this line, and added next two lines.
   StringReplace, name, A_LoopField, ., _, a
   hbmp := CreateBitmap_%name%()
   DllCall("ImageList_Add", "Ptr",himl, "Ptr",hbmp, "Ptr",0)
   DllCall("DeleteObject", "Ptr", hbmp) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

The bitmap is deleted after adding it to the image list. That's why you have to call CreateBitmap_%name%(True) on subsequent calls, if you want to use the same bitmap more than once. Otherwise the function will return the handle created by the first call, pointing to a bitmap which don't exist any more.


Prefer ahkscript.org for the time being.


Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

Related :

Rseding91's function to "Include virtually any file in a script"
    www.autohotkey.com/board/topic/64481-include-virtually-any-file-in-a-script-exezipdlletc/


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

The bitmap is deleted after adding it to the image list. That's why you have to call CreateBitmap_%name%(True) on subsequent calls, if you want to use the same bitmap more than once. Otherwise the function will return the handle created by the first call, pointing to a bitmap which don't exist any more.

Thank you so much! works now.



tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

Is it Possible support .ico images?

 

Because I want to add transparent image into button, I use ILButton(), but ILButton() doesn't support gif/png.



Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

Is it Possible support .ico images?

 

Because I want to add transparent image into button, I use ILButton(), but ILButton() doesn't support gif/png.

http://www.autohotke...t-exezipdlletc/


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

@Rijul Ahuja

 

Thank you. The script you point to will extract file to location path (like FileInstall), which is not the way I like. I prefer load image into memory.

 

Currently I add icons to the AutoHotkeySC.bin using Resource Hacker, and load icons from the compiled exe. It works, but more steps than Image2Include.



just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

To get a HICON handle just change
 
   DllCall(""Gdiplus.dll\GdipCreateHBITMAPFromBitmap"", ""Ptr"", pBitmap, ""PtrP"", hBitmap, ""UInt"", 0)
 
to
 
   DllCall(""Gdiplus.dll\GdipCreateHICONFromBitmap"", ""Ptr"", pBitmap, ""PtrP"", hBitmap, ""UInt"", 0)
 
and tell me whether it does what you want, please.


Prefer ahkscript.org for the time being.


tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

It works! Thanks a lot.



just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

Update: Added support for icons (THX, tmplinshi)


Prefer ahkscript.org for the time being.


tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012

Hi, just me. I'm so sorry, I made a mistake sad.png , it seems the icon format doesn't work...
 
Today I am going to change CreateBitmap_name_ext to Create_name_ext in the ILButton.ahk, then I just noticed, that the code hbmp := CreateBitmap_%name%(True) is commented. Which means in my last test, actually it loads from the icon file, not the Include script.

Sorry about this.