How to output ico file from blob data type of sqlite database? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

How to output ico file from blob data type of sqlite database?

13 Jan 2024, 05:52

I am trying to read Chrome's bookmark icon files.

Bookmark icons are stored in an SQLite database named Favicons under user profile directory.
%LocalAppData%\Google\Chrome\User Data\Profile 1\
The icon images are stored (in png format, BLOB data type) in the "image_data" field in "favicon_bitmaps" table.
The icon images could be indexed by "icon_id" as below.

But the *.png file is stored in the database in the format of BLOB
I would like to output *.ico file directly from the BLOB data(png file) as below, without writing to hard disk and converting the format.
Database structure: https://github.com/valuex/AutohotkeyScripts/blob/main/Chrome_GetIcon.md
Blob2hBitmap(Blob_Buffer) and hBitmap2Icon(hBitmap, destIco) are from AHK forum.
But Blob2hBitmap(Blob_Buffer) is in V1.
I tried to convert it into V2, but not successful. The error message says as below.
error message snapshot: https://github.com/valuex/AutohotkeyScripts/blob/main/Chrome_GetIcon.md
Any help on fixing it would be appreciated. :)

Code: Select all

Stream.Release()  ;Error: This value of type "Integer" has no method named "Release".

Code: Select all

#Requires AutoHotkey 2.0

#Include  .\lib\Class_SQLiteDB.ahk
#Include  .\lib\Gdip_All.ahk

db_file:=A_ScriptDir . "\Favicons"

DB := SQLiteDB()  ; read Favicons to get bookmark icon file
DB.OpenDB(db_file)

search_result:=Get_Icon_File(1) ; blob, buffer object

pToken := Gdip_Startup()
IconName:=A_ScriptDir . "\1.ico"
PngBlob2Ico(search_result,IconName) ; directly output  ico file from blob

Gdip_Shutdown(pToken )

Get_Icon_File(icon_id_number)
{
    sql_cmd  := 'SELECT image_data FROM favicon_bitmaps WHERE icon_id =' . icon_id_number . ' AND width = 16;'
    If !DB.Query(sql_cmd, &query_result)
    {
        MsgBox("SQLite QUERY Error`n`nMessage: " . DB.ErrorMsg . "`nCode: " . DB.ErrorCode . "`nFile: " . db_file . "`nQuery: " . sql_cmd)
        return 0
    }

    search_result := ''
    Loop
    {
        result := query_result.Next(&row)
        If !result
        {
            MsgBox("SQLite NEXT Error`n`nMessage: " . DB.ErrorMsg . "`nCode: " . DB.ErrorCode)
            return 0
        }
        If result = -1
        {
            Break
        }
        search_result := row[1]
        query_result.Free()
        return search_result
    }
}

PngBlob2Ico(blob,destIco)
{
    hBitmap :=Blob2hBitmap(blob)
    hBitmap2Icon(hBitmap, destIco)

    ;https://www.autohotkey.com/boards/viewtopic.php?t=124212&p=552266#p552266
    Blob2hBitmap(Blob_Buffer)
    {
        Size := Blob_Buffer.Size 
        Addr := Blob_Buffer.Ptr
        hBitmap := Gdip_CreateHBitmapFomData(Addr, Size)
        return hBitmap
        ;https://www.autohotkey.com/boards/viewtopic.php?t=124212&p=552266#p552266
        Gdip_CreateHBitmapFomData(DataPtr, DataSize) {
            Local Bitmap := 0, HBitMap := 0
            If (Bitmap := Gdip_CreateBitmapFromData(DataPtr, DataSize)) {
               HBitMap := Gdip_CreateHBITMAPFromBitmap(Bitmap)
               Gdip_DisposeImage(Bitmap)
            }
            Return HBitmap
         }
         
         Gdip_CreateBitmapFromData(DataPtr, DataSize) {
            Local Bitmap := 0, Stream := 0, HR := 0
            If (Stream := DllCall("Shlwapi.dll\SHCreateMemStream", "Ptr", DataPtr, "UInt", DataSize, "UPtr")) {
               HR := DllCall("Gdiplus.dll\GdipCreateBitmapFromStream", "Ptr", Stream, "PtrP", Bitmap, "UInt")
               Stream.Release()
            }
            Return (HR ? 0 : Bitmap)
         }

    }

    ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=93750&p=550636#p550523
    hBitmap2Icon(hBitmap, destIco) {
        ; hBitmap := LoadPicture(sourcePng,"GDI+")
        hIcon := HIconFromHBitmap(hBitmap)
        HiconToFile(hIcon, destIco)
        DllCall("DestroyIcon", "Ptr", hIcon), DllCall("DeleteObject", "Ptr", hBitmap)

        HIconFromHBitmap(hBitmap) {
            BITMAP := Buffer(size := 4*4 + A_PtrSize*2, 0)
            DllCall("GetObject", "Ptr", hBitmap, "Int", size, "Ptr", BITMAP)
            width := NumGet(BITMAP, 4, "UInt"), height := NumGet(BITMAP, 8, "UInt")
            hDC := DllCall("GetDC", "Ptr", 0, "Ptr")
            hCBM := DllCall("CreateCompatibleBitmap", "Ptr", hDC, "Int", width, "Int", height, "Ptr")
            ICONINFO := Buffer(4*2 + A_PtrSize*3, 0)
        
            NumPut("Int", 1, ICONINFO)
            NumPut("Ptr", hCBM, ICONINFO, 4*2 + A_PtrSize)
            NumPut("Ptr", hBitmap, ICONINFO, 4*2 + A_PtrSize*2)
        
            hIcon := DllCall("CreateIconIndirect", "Ptr", ICONINFO, "Ptr")
            DllCall("DeleteObject", "Ptr", hCBM), DllCall("ReleaseDC", "Ptr", 0, "Ptr", hDC)
            Return hIcon
        }
        
        HiconToFile(hIcon, destFile) {
            static szICONHEADER := 6, szICONDIRENTRY := 16, szBITMAP := 16 + A_PtrSize*2, szBITMAPINFOHEADER := 40
                 , IMAGE_BITMAP := 0, flags := (LR_COPYDELETEORG := 0x8) | (LR_CREATEDIBSECTION := 0x2000)
                 , szDIBSECTION := szBITMAP + szBITMAPINFOHEADER + 8 + A_PtrSize*3
                 , copyImageParams := ["UInt", IMAGE_BITMAP, "Int", 0, "Int", 0, "UInt", flags, "Ptr"]
        
            ICONINFO := Buffer(8 + A_PtrSize*3, 0)
            DllCall("GetIconInfo", "Ptr", hIcon, "Ptr", ICONINFO)
            if !hbmMask  := DllCall("CopyImage", "Ptr", NumGet(ICONINFO, 8 + A_PtrSize, "UPtr"), copyImageParams*) {
                MsgBox("CopyImage failed. LastError: " . A_LastError)
                Return
            }
            hbmColor := DllCall("CopyImage", "Ptr", NumGet(ICONINFO, 8 + A_PtrSize*2, "UPtr"), copyImageParams*)
            mskDIBSECTION := Buffer(szDIBSECTION, 0)
            clrDIBSECTION := Buffer(szDIBSECTION, 0)
            DllCall("GetObject", "Ptr", hbmMask, "Int", szDIBSECTION, "Ptr", mskDIBSECTION)
            DllCall("GetObject", "Ptr", hbmColor, "Int", szDIBSECTION, "Ptr", clrDIBSECTION)
        
            clrWidth        := NumGet(clrDIBSECTION, 4, "UInt")
            clrHeight       := NumGet(clrDIBSECTION, 8, "UInt")
            clrBmWidthBytes := NumGet(clrDIBSECTION, 12, "UInt")
            clrBmPlanes     := NumGet(clrDIBSECTION, 16, "UShort")
            clrBmBitsPixel  := NumGet(clrDIBSECTION, 18, "UShort")
            clrBits         := NumGet(clrDIBSECTION, 16 + A_PtrSize, "UPtr")
            colorCount := clrBmBitsPixel >= 8 ? 0 : 1 << (clrBmBitsPixel * clrBmPlanes)
            clrDataSize := clrBmWidthBytes * clrHeight
        
            mskHeight       := NumGet(mskDIBSECTION, 8, "UInt")
            mskBmWidthBytes := NumGet(mskDIBSECTION, 12, "UInt")
            mskBits         := NumGet(mskDIBSECTION, 16 + A_PtrSize, "UPtr")
            mskDataSize := mskBmWidthBytes * mskHeight
        
            iconDataSize := clrDataSize + mskDataSize
            dwBytesInRes := szBITMAPINFOHEADER + iconDataSize
            dwImageOffset := szICONHEADER + szICONDIRENTRY
        
            ICONHEADER := Buffer(szICONHEADER, 0)
            NumPut("UShort", 1, ICONHEADER, 2)
            NumPut("UShort", 1, ICONHEADER, 4)
        
            ICONDIRENTRY := Buffer(szICONDIRENTRY, 0)
            NumPut("UChar", clrWidth, ICONDIRENTRY, 0)
            NumPut("UChar", clrHeight, ICONDIRENTRY, 1)
            NumPut("UChar", colorCount, ICONDIRENTRY, 2)
            NumPut("UShort", clrBmPlanes, ICONDIRENTRY, 4)
            NumPut("UShort", clrBmBitsPixel, ICONDIRENTRY, 6)
            NumPut("UInt", dwBytesInRes, ICONDIRENTRY, 8)
            NumPut("UInt", dwImageOffset, ICONDIRENTRY, 12)
        
            NumPut("UInt", clrHeight*2, clrDIBSECTION, szBITMAP +  8)
            NumPut("UInt", iconDataSize, clrDIBSECTION, szBITMAP + 20)
            
            File := FileOpen(destFile, "w", "cp0")
            File.RawWrite(ICONHEADER, szICONHEADER)
            File.RawWrite(ICONDIRENTRY, szICONDIRENTRY)
            File.RawWrite(clrDIBSECTION.Ptr + szBITMAP, szBITMAPINFOHEADER)
            File.RawWrite(clrBits + 0, clrDataSize)
            File.RawWrite(mskBits + 0, mskDataSize)
            File.Close()
        
            DllCall("DeleteObject", "Ptr", hbmColor)
            DllCall("DeleteObject", "Ptr", hbmMask)
        }
    }    
    
}

Attachments
Question.zip
Main script and lib files, database
(1.73 MiB) Downloaded 11 times
just me
Posts: 9542
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to output ico file from blob data type of sqlite database?

13 Jan 2024, 08:55

Try

Code: Select all

ObjRelease(Stream)
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

13 Jan 2024, 21:51

I've tried to use

Code: Select all

            ;    Stream.Release()
               ObjRelease(Stream)
[Mod edit: Replaced url tags with code tags.]

It will solve the previous problem.
However, a new error comes out, saying:

Code: Select all

File.RawWrite(clrBits + 0, clrDataSize)  ;Error: Parameter #1 of File.Prototype.RawWrite is invalid.
And if I ignore this error, the output ico file is with false data and cannot be opened.
The gdi-class related memory opertation is far above my knowledge.
Could you help to give further instruction on fixing it?
Thanks.
just me
Posts: 9542
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 06:41

In v2 you don't need the clrBits + 0 but that should not cause the error. Did you check the contents of clrBits and the returned size from

Code: Select all

            DllCall("GetObject", "Ptr", hbmMask, "Int", szDIBSECTION, "Ptr", mskDIBSECTION)
            DllCall("GetObject", "Ptr", hbmColor, "Int", szDIBSECTION, "Ptr", clrDIBSECTION)
?
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 10:17

Code: Select all

            DllCall("GetObject", "Ptr", hbmMask, "Int", szDIBSECTION, "Ptr", mskDIBSECTION)
            DllCall("GetObject", "Ptr", hbmColor, "Int", szDIBSECTION, "Ptr", clrDIBSECTION)
both mskDIBSECTION.Size and clrDIBSECTION.Size is 104.

As for clrBits, it is 0.
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 10:39

I think it has something to do with the function Blob2hBitmap(Blob_Buffer).
The two variables Bitmap and HBitMap is 0.

Code: Select all

        Gdip_CreateHBitmapFomData(DataPtr, DataSize) {
            Local Bitmap := 0, HBitMap := 0
            If (Bitmap := Gdip_CreateBitmapFromData(DataPtr, DataSize)) {
               HBitMap := Gdip_CreateHBITMAPFromBitmap(Bitmap)
               Gdip_DisposeImage(Bitmap)
            }
            mm Bitmap
            mm HBitmap
            Return HBitmap
         }
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 10:48

I get it.

Code: Select all

HR := DllCall("Gdiplus.dll\GdipCreateBitmapFromStream", "Ptr", Stream, "PtrP", Bitmap, "UInt")
should be changed into

Code: Select all

HR := DllCall("Gdiplus.dll\GdipCreateBitmapFromStream", "Ptr", Stream, "PtrP",[u] &Bitmap[/u], "UInt")
Then it works.
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 10:54

I would like to share the whole function to directly output ico file from Sqlite blob data here.
Credit goes to:
@just me: viewtopic.php?t=124212&p=552266#p552266
@fade2gray: viewtopic.php?style=17&t=93750&p=550636#p550523

Code: Select all

PngBlob2Ico(blob,destIco)
{
    hBitmap :=Blob2hBitmap(blob)
    hBitmap2Icon(hBitmap, destIco)

    ;https://www.autohotkey.com/boards/viewtopic.php?t=124212&p=552266#p552266
    Blob2hBitmap(Blob_Buffer)
    {
        Size := Blob_Buffer.Size 
        Addr := Blob_Buffer.Ptr
        ; Addr := Blob_Buffer
        hBitmap := Gdip_CreateHBitmapFomData(Addr, Size)
        return hBitmap
        ;https://www.autohotkey.com/boards/viewtopic.php?t=124212&p=552266#p552266
        Gdip_CreateHBitmapFomData(DataPtr, DataSize) {
            Local Bitmap := 0, HBitMap := 0
            If (Bitmap := Gdip_CreateBitmapFromData(DataPtr, DataSize)) {
               HBitMap := Gdip_CreateHBITMAPFromBitmap(Bitmap)
               Gdip_DisposeImage(Bitmap)
            }
            Return HBitmap
         }
         
         Gdip_CreateBitmapFromData(DataPtr, DataSize) {
            Local Bitmap := 0, Stream := 0, HR := 0
            Stream := DllCall("Shlwapi.dll\SHCreateMemStream", "Ptr", DataPtr, "UInt", DataSize, "UPtr")
            If (Stream) {
               HR := DllCall("Gdiplus.dll\GdipCreateBitmapFromStream", "Ptr", Stream, "PtrP", &Bitmap, "UInt")
               ObjRelease(Stream)
            }  
            Return (HR ? 0 : Bitmap)
         }

    }

    ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=93750&p=550636#p550523
    hBitmap2Icon(hBitmap, destIco) {
        ; hBitmap := LoadPicture(sourcePng,"GDI+")
        hIcon := HIconFromHBitmap(hBitmap)
        HiconToFile(hIcon, destIco)
        DllCall("DestroyIcon", "Ptr", hIcon), DllCall("DeleteObject", "Ptr", hBitmap)

        HIconFromHBitmap(hBitmap) {
            BITMAP := Buffer(size := 4*4 + A_PtrSize*2, 0)
            DllCall("GetObject", "Ptr", hBitmap, "Int", size, "Ptr", BITMAP)
            width := NumGet(BITMAP, 4, "UInt"), height := NumGet(BITMAP, 8, "UInt")
            hDC := DllCall("GetDC", "Ptr", 0, "Ptr")
            hCBM := DllCall("CreateCompatibleBitmap", "Ptr", hDC, "Int", width, "Int", height, "Ptr")
            ICONINFO := Buffer(4*2 + A_PtrSize*3, 0)
        
            NumPut("Int", 1, ICONINFO)
            NumPut("Ptr", hCBM, ICONINFO, 4*2 + A_PtrSize)
            NumPut("Ptr", hBitmap, ICONINFO, 4*2 + A_PtrSize*2)
        
            hIcon := DllCall("CreateIconIndirect", "Ptr", ICONINFO, "Ptr")
            DllCall("DeleteObject", "Ptr", hCBM), DllCall("ReleaseDC", "Ptr", 0, "Ptr", hDC)
            Return hIcon
        }
        
        HiconToFile(hIcon, destFile) {
            static szICONHEADER := 6, szICONDIRENTRY := 16, szBITMAP := 16 + A_PtrSize*2, szBITMAPINFOHEADER := 40
                 , IMAGE_BITMAP := 0, flags := (LR_COPYDELETEORG := 0x8) | (LR_CREATEDIBSECTION := 0x2000)
                 , szDIBSECTION := szBITMAP + szBITMAPINFOHEADER + 8 + A_PtrSize*3
                 , copyImageParams := ["UInt", IMAGE_BITMAP, "Int", 0, "Int", 0, "UInt", flags, "Ptr"]
        
            ICONINFO := Buffer(8 + A_PtrSize*3, 0)
            DllCall("GetIconInfo", "Ptr", hIcon, "Ptr", ICONINFO)
            if !hbmMask  := DllCall("CopyImage", "Ptr", NumGet(ICONINFO, 8 + A_PtrSize, "UPtr"), copyImageParams*) {
                MsgBox("CopyImage failed. LastError: " . A_LastError)
                Return
            }
            hbmColor := DllCall("CopyImage", "Ptr", NumGet(ICONINFO, 8 + A_PtrSize*2, "UPtr"), copyImageParams*)
            mskDIBSECTION := Buffer(szDIBSECTION, 0)
            clrDIBSECTION := Buffer(szDIBSECTION, 0)
            DllCall("GetObject", "Ptr", hbmMask, "Int", szDIBSECTION, "Ptr", mskDIBSECTION)
            DllCall("GetObject", "Ptr", hbmColor, "Int", szDIBSECTION, "Ptr", clrDIBSECTION)
        
            clrWidth        := NumGet(clrDIBSECTION, 4, "UInt")
            clrHeight       := NumGet(clrDIBSECTION, 8, "UInt")
            clrBmWidthBytes := NumGet(clrDIBSECTION, 12, "UInt")
            clrBmPlanes     := NumGet(clrDIBSECTION, 16, "UShort")
            clrBmBitsPixel  := NumGet(clrDIBSECTION, 18, "UShort")
            clrBits         := NumGet(clrDIBSECTION, 16 + A_PtrSize, "UPtr")
            colorCount := clrBmBitsPixel >= 8 ? 0 : 1 << (clrBmBitsPixel * clrBmPlanes)
            clrDataSize := clrBmWidthBytes * clrHeight
        
            mskHeight       := NumGet(mskDIBSECTION, 8, "UInt")
            mskBmWidthBytes := NumGet(mskDIBSECTION, 12, "UInt")
            mskBits         := NumGet(mskDIBSECTION, 16 + A_PtrSize, "UPtr")
            mskDataSize := mskBmWidthBytes * mskHeight
        
            iconDataSize := clrDataSize + mskDataSize
            dwBytesInRes := szBITMAPINFOHEADER + iconDataSize
            dwImageOffset := szICONHEADER + szICONDIRENTRY
        
            ICONHEADER := Buffer(szICONHEADER, 0)
            NumPut("UShort", 1, ICONHEADER, 2)
            NumPut("UShort", 1, ICONHEADER, 4)
        
            ICONDIRENTRY := Buffer(szICONDIRENTRY, 0)
            NumPut("UChar", clrWidth, ICONDIRENTRY, 0)
            NumPut("UChar", clrHeight, ICONDIRENTRY, 1)
            NumPut("UChar", colorCount, ICONDIRENTRY, 2)
            NumPut("UShort", clrBmPlanes, ICONDIRENTRY, 4)
            NumPut("UShort", clrBmBitsPixel, ICONDIRENTRY, 6)
            NumPut("UInt", dwBytesInRes, ICONDIRENTRY, 8)
            NumPut("UInt", dwImageOffset, ICONDIRENTRY, 12)
        
            NumPut("UInt", clrHeight*2, clrDIBSECTION, szBITMAP +  8)
            NumPut("UInt", iconDataSize, clrDIBSECTION, szBITMAP + 20)
            
            File := FileOpen(destFile, "w", "cp0")
            File.RawWrite(ICONHEADER, szICONHEADER)
            File.RawWrite(ICONDIRENTRY, szICONDIRENTRY)
            File.RawWrite(clrDIBSECTION.Ptr + szBITMAP, szBITMAPINFOHEADER)
            File.RawWrite(clrBits + 0, clrDataSize)
            File.RawWrite(mskBits + 0, mskDataSize)
            File.Close()
        
            DllCall("DeleteObject", "Ptr", hbmColor)
            DllCall("DeleteObject", "Ptr", hbmMask)
        }
    }    
    
}

iseahound
Posts: 1459
Joined: 13 Aug 2016, 21:04
Contact:

Re: How to output ico file from blob data type of sqlite database?

14 Jan 2024, 12:46

wait, you're probably overthinking this one.

There's a shortcut, because Microsoft allows you to use PNGs as ICO files.

Source: viewtopic.php?style=7&t=36636&p=168805
Modified: viewtopic.php?p=524692

Code: Select all

Persistent
Base64PNG := ' ; Small 16px x 16px green leaf
(
    iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABpElEQVR42p2TQShEURiFb6ZmMS
    sLWSilzEwUReyUBZmVjY2SKGWBBVKahSxISFHYGbFAEouRlDTKYiJFo4wFVsLC0kKN1fV/d+bq
    zsukvDq9+95/zvnPf+97Sv1xtUyqSHNUrQpuBBp0LZXrzmW/jkyrTCFRQLArBD24UaHXkr36ID
    Wqk29Rs75+X9HD29U6HFHdv4mnEC6ctOnEc1YUf+gwArD31KQnEj6SvAg94BXf0hERXXpiRYZs
    DdfTYT17lX0nY6QLiiHSvX9LGTHxrRhgJgnuXPEMm3L/OWdEkIhNAmJz5z0Y2ZcE8aAWjf4xEL
    cMAuabT1QZEsCUUcDR44DeTLWaOnevgREvJksNMXdEZk10ZrYYP1aGl2fAg52PPUDMcWHgFVt4
    E1wwn7vjgCTMb+e2o4E8g8Y+NWTJ7DgnYOHOTgO7N9L01B1hBzEjIPLGdTvDo3tJSNUasUQ+tE
    dHEXeICK0Rz3CoIZZPuF2kPtv9jGLO+VWKYxLvEqIHX/I+JpIGgd/9CINSOBfCh6xrBMWCUI7o
    ol5QVuivrRTUqX9c354hhkwsQvG0AAAAAElFTkSuQmCC
)'

TraySetIcon('HICON: ' . Base64PNG_to_HICON(Base64PNG))

Base64PNG_to_HICON(Base64PNG, height := 16) {
    size := StrLen( RTrim(Base64PNG, '=') )*3//4
    if DllCall('Crypt32\CryptStringToBinary', 'Str', Base64PNG, 'UInt', StrLen(Base64PNG), 'UInt', 1,
                                              'Ptr', buf := Buffer(size), 'UIntP', &size, 'Ptr', 0, 'Ptr', 0)
        return DllCall('CreateIconFromResourceEx', 'Ptr', buf, 'UInt', size, 'UInt', true,
                                                   'UInt', 0x30000, 'Int', height, 'Int', height, 'UInt', 0)
    return 0
}
I don't believe it works with your HiconToFile(hIcon, destFile) function, I can't tell. I'll leave this as a note for anyone who wants to pick up this work in the future.

The idea is that this single line: DllCall('CreateIconFromResourceEx', 'Ptr', buf, 'UInt', size, 'UInt', true, 'UInt', 0x30000, 'Int', height, 'Int', height, 'UInt', 0) turns your binary blob into an HIcon.
just me
Posts: 9542
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to output ico file from blob data type of sqlite database?  Topic is solved

16 Jan 2024, 06:26

@iseahound,
thanks. And after some more reading about PNG icons there's another 'shortcut' to save PNG data as ICO files:

Code: Select all

; ======================================================================================================================
; Saves a PNG image passed in PngBuffer as icon in the ICO file specified by IcoFile.
;     PngBuffer:  Buffer object containing the complete contents of the PNG file.
;     IcoFile:    Name/Path of the ICO file.
; ======================================================================================================================
SavePngBufferAsICO(PngBuffer, IcoFile) {
   Local ICONHEADER := Buffer(6, 0)
   NumPut("Short", 1, "Short", 1, ICONHEADER, 2)
   Local ICONDIRENTRY := Buffer(16, 0)
   NumPut("Short", 32, "UInt", PngBuffer.Size, "UInt", 22, ICONDIRENTRY, 6)
   Try {
      FileObj := FileOpen(IcoFile, "w", "CP0")
      FileObj.RawWrite(ICONHEADER)
      FileObj.RawWrite(ICONDIRENTRY)
      FileObj.RawWrite(PngBuffer)
      FileObj.Close()
   }
   Catch
      Throw Error("Could not create file " IcoFile "!`nA_LastError: " A_LastError, -1)
   Return True
}
valuex
Posts: 86
Joined: 01 Nov 2014, 08:17

Re: How to output ico file from blob data type of sqlite database?

03 Feb 2024, 21:11

It's pretty neat and concise . Thank you very much.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: docterry, Google [Bot] and 44 guests