Sign in to follow this  
Followers 0
Andreik

Create Icons

4 posts in this topic

#1 ·  Posted (edited)

Using wikipedia I wrote a function to create valid icons but something is wrong and I can't figure out.

CreateICO("test.ico","icon.bmp",32,32)

Func CreateICO($ICO_OUT,$BMP_IN,$W,$H)
    Local $BMP_FILE = FileOpen($BMP_IN,16)
    Local $BITMAP = FileRead($BMP_FILE)
    FileClose($BMP_FILE)
    Local $BM_SIZE = StringTrimLeft(BinaryMid($BITMAP,3,4),2)
    Local $ICO = Binary("0x0000" & _                ;2Bytes Reserved
                        "0100" & _                  ;2Bytes Specifies image type: 1 for icon
                        "0100" & _                  ;2Bytes Specifies number of images in the file.
                        Hex($W,2) & _               ;1Byte Specifies image width in pixels
                        Hex($H,2) & _               ;1Byte Specifies image height in pixels
                        "00" & _                    ;1Byte Specifies number of colors in the color palette
                        "00" & _                    ;1Byte Reserved
                        "0100" & _                  ;2Bytes Specifies color planes
                        "1800" & _                  ;2Bytes Specifies bits per pixel
                        $BM_SIZE & _                ;4Bytes Specifies the size of the bitmap data in bytes
                        "16000000")                 ;4Bytes Specifies the offset of BMP or PNG data in the file
    Local $OUTPUT = FileOpen($ICO_OUT,18)
    FileWrite($OUTPUT,$ICO & StringTrimLeft($BITMAP,30))    ;Icon Header & Bitmap Data
    FileClose($OUTPUT)
EndFunc

Here I attach the bitmap for test and a valid ico created from this bitmap. According to wikipedia this function should work.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites



I opened the icon file your script generates and the icon you want to reproduce. I see two things wrong:

1. It appears identical except for $BM_SIZE. I don't understand your equation for calculating the size. Also, a quick look on Wiki says there are different types of bmps, so you may need to compensate for the what version it is.

2. It writes the file up until about half way and stops (using Tiny Hexer, it shows that it stops 0x0c30 and the icon that you gave goes to 0x18f0). Is there a limit on how much fileread can take in?


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yeah it's different, I don't know why as long $BM_SIZE contain the size of bitmap data read from the bitmap file. But from what I see it's not the only difference, the valid icon have 128 bytes more after bitmap data section, filled with 0x00, this can be a possible explanation why $BM_SIZE is different then in valid ico. Anyway this is weird and I can't figure out.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Nice example by smashly here:

Br,

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!
¯\_(ツ)_/¯

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  
Followers 0