Jump to content

Recommended Posts

Posted (edited)

Hello,

I've got a SQLite database (not created by me) which has thumbnails stored in it in a BLOB field. If I paste the raw data from the field into Notepad, turn on word wrap and resize it I can see an ASCII representation of the image.

EDIT: Or if you load it using DOS command, EDIT /176 test.txt

Is there anyway to identify what format the original image is (or does anyone recognise the format)?

The attached test.txt is the raw data I extracted for an image of the 'Peppa Pig' logo.

Any help appreciated.

Thanks,

NiVZ

test.txt

Edited by NiVZ
Posted

Notepad is a _text_ editor and unlikely to show you anything useful. Rather use any hex editor to see the actual file content.

Now, to your SQLite blob question, try downloading SQLite Expert. It has the feature to show you images directly (and embeds an hex editor as well).

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Hi jchd,

I tried SQLite Expert, but the image viewer just shows a black box.

I understand Notepad is a text editor, but I did say it gives an ASCII art style representation of the image, in much the way that an .xpm or other character based image saving formats use - I just can't identify this one. Tried renaming it to all the usual extensions, but I fear that the header info may also have been stripped out before the image was saved to the database as a BLOB.

Thanks,

NiVZ

Posted

  On 3/20/2012 at 12:03 PM, 'NiVZ said:

Is there anyway to identify what format the original image is (or does anyone recognise the format)?

Using IDENTIFY from the ImageMagick package provided the following data.

  Reveal hidden contents

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Posted (edited)

Thanks JohnQSmith,

Not sure what a lot of that information means. These images are very small, probably around 30x20 pixels so the resolution ImageMagik is suggesting is far too big :oops:

I think it's using some sort of pixmap format (http://www.franz.com/support/documentation/6.2/doc/cg/cg-pixmaps.htm), but I can't see anywhere in the file where it stores colour information.

Thanks,

NiVZ

Edited by NiVZ
Posted (edited)

Yeah, after converting it to a JPG and viewing it, it appeared to have interpreted as some sort of a hex dump. I'll see if I can take another look at it.

Edit: Sorry. No joy.

Edited by JohnQSmith

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Posted

From the little that made thru in text mode I suspect the file is merely a raw bitmap in 16-bit color (possibly 5-6-5) or grayscale.

Can you post the same blob (not truncated by text mode) in binary format after taking care that you grab it in full length?

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Hello,

The images are definitely in colour and not grayscale.

I extracted the image info using sqlite browser 2.0 beta 1 from Sourceforge by double clicking the field and then clicking Extract. But I do notice the data is different when viewed in the database. Doesn't seem to be anyway to extract it in Binary using Sqlite browser so I've uploaded the database with 1 record in the Videos table.

I had to rename it to from .db to .txt to upload it.

Thanks for taking the time to look at this,

NiVZ

test.txt

Posted (edited)

Thanks. The blob is 0x3C80 = 15488 bytes long. I'd make the guess that pixels are 16-bits and the image has 15488 / 2 = 7744 pixels. 7744 = 26 × 112 = From images I googled, the picture should be rectangular, maybe 64 × 121 or why not may be perfect squares 88 × 88 !

I'll experiment with this and tell you how it cooks. Done!

I was correct about the image format: 88 × 88, 16-bit per pixel (little-endian) as 5-6-5 (RGB)

Edited by jchd
  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Hello,

I checked on the display and the thumbnails are square.

My goal now is to be able to convert to and from this format. I'll need to read up on 5-6-5 RGB and see how I get on.

Many thanks for looking at this, really appreciate your help :oops:

NiVZ

Edited by NiVZ
Posted (edited)

Hello, here is an example for reading the image, and creating a GDI-Bitmap in order to show it in a GUI:

#include<winapi.au3>
#include<sqlite.au3>
#include<windowsconstants.au3>

_SQLite_Startup()
_SQLite_Open(@ScriptDir & "img.bin")

Global $aRow
_SQLite_QuerySingleRow(-1, "SELECT thumbnail FROM Videos LIMIT 1", $aRow)

_SQLite_Close()
_SQLite_Shutdown()


GUICreate("Test")
$imgIcon = GUICtrlCreatePic("", 10, 10, 88, 88)
GUISetState()

$hLblDC = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)


$tData = DllStructCreate("byte[" & BinaryLen($aRow[0]) & "]")
DllStructSetData($tData, 1, $aRow[0])

$tBITMAPINFOHEADER  = DllStructCreate("DWORD biSize;LONG  biWidth;LONG  biHeight;WORD  biPlanes;WORD  biBitCount;DWORD biCompression;DWORD biSizeImage;LONG  biXPelsPerMeter;LONG  biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant; DWORD colormap[3]")
DllStructSetData($tBITMAPINFOHEADER, 1, DllStructGetSize($tBITMAPINFOHEADER))
DllStructSetData($tBITMAPINFOHEADER, 2, 88)
DllStructSetData($tBITMAPINFOHEADER, 3, -88)
DllStructSetData($tBITMAPINFOHEADER, 4, 1)
DllStructSetData($tBITMAPINFOHEADER, 5, 16)

; use default GDI32 16 bit format: 5-5-5
DllStructSetData($tBITMAPINFOHEADER,  6, 0)

; Choose Colormask manually, example for 5-5-5
;~ DllStructSetData($tBITMAPINFOHEADER,  6, 3) ;BI_BITFIELDS
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x7C00, 1) ;- Red mask
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x03E0, 2) ;- Green mask
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x001F, 3) ;- Blue mask


_WinAPI_SetDIBits($hLblDC, $hBitmap, 0, 88, DllStructGetPtr($tData), DllStructGetPtr($tBITMAPINFOHEADER), 1)

_WinAPI_ReleaseDC(GUICtrlGetHandle($imgIcon), $hLblDC)
_WinAPI_DeleteDC($hDC)

_GUICtrlStatic_SetImage($imgIcon, $hBitmap)



While GUIGetMsg()<>-3
WEnd




; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                  $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success      - 1
;                  Failure      - 0 and set @error:
;                  |1  - invalid $pSource
;                  |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

Nice shot ProgAndy!

You're right, it was 5-5-5 and not 5-6-5.

I was fighting with GDI+ to create a bitmap from scratch but didn't see how to do that.

I'm very ignorant at Windows graphics.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

  On 3/22/2012 at 11:12 AM, 'jchd said:

Nice shot ProgAndy!

You're right, it was 5-5-5 and not 5-6-5.

I was fighting with GDI+ to create a bitmap from scratch but didn't see how to do that.

I'm very ignorant at Windows graphics.

I tried 565, but the picture looked really bad :oops:

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted (edited)

Wow, thank you both very much :oops: Especially for the GUI program @ProgAndy

It's really good being able to see the image.

My final question (I know sorry) is, how do I now load an image to insert back into the database (ie add new images or replace existing ones)?

I'm happy enough using _GDIPlus_LoadImageFromFile and using SQLite to do the Insert/replace statement. I just don't know how to manipulate the image I load using GDIPlus into the RGB 555 stream (with no header?)

Here's the code with an added File selection dialog which creates a GDIPlus bitmap (and replaces the currently shown image)

#include<sqlite.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>

$GUI    = GUICreate("Test")
$imgIcon   = GUICtrlCreatePic("", 10, 10, 88, 88)
$btnGetImage = GUICtrlCreateButton("Choose Image", 10, 100, 100, 20)
GUISetState()
$hLblDC  = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap  = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC   = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)
$hLblDC  = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap  = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC   = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)
_GDIPlus_Startup()
_SQLite_Startup()
$hDB = _SQLite_Open(@ScriptDir & "Test.db")
Global $aRow
_SQLite_QuerySingleRow(-1, "SELECT thumbnail FROM Videos LIMIT 1", $aRow)

$tData = DllStructCreate("byte[" & BinaryLen($aRow[0]) & "]")
DllStructSetData($tData, 1, $aRow[0])

; Bitmap Header info
$tBITMAPINFOHEADER  = DllStructCreate("DWORD biSize;LONG  biWidth;LONG  biHeight;WORD  biPlanes;WORD  biBitCount;DWORD biCompression;DWORD biSizeImage;LONG  biXPelsPerMeter;LONG  biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant; DWORD colormap[3]")
DllStructSetData($tBITMAPINFOHEADER, 1, DllStructGetSize($tBITMAPINFOHEADER))
DllStructSetData($tBITMAPINFOHEADER, 2, 88)
DllStructSetData($tBITMAPINFOHEADER, 3, -88)
DllStructSetData($tBITMAPINFOHEADER, 4, 1)
DllStructSetData($tBITMAPINFOHEADER, 5, 16)
; use default GDI32 16 bit format: 5-5-5
DllStructSetData($tBITMAPINFOHEADER,  6, 0)
_WinAPI_SetDIBits($hLblDC, $hBitmap, 0, 88, DllStructGetPtr($tData), DllStructGetPtr($tBITMAPINFOHEADER), 1)
_WinAPI_ReleaseDC(GUICtrlGetHandle($imgIcon), $hLblDC)
_WinAPI_DeleteDC($hDC)
_GUICtrlStatic_SetImage($imgIcon, $hBitmap)

While 1
  
   $nMsg = GuiGetMsg()
  
   If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop
  
   If $nMsg = $btnGetImage Then
   $sFilename = FileOpenDialog("Choose Image...", @DesktopDir, "Images(*.jpg;*.bmp)|All (*.*)", 3, "", $GUI)
   If @Error Then
   ; Do nothing
   Else

   $Bitmap = _GDIPlus_BitmapCreateFromFile($sFilename)
   $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
   _GUICtrlStatic_SetImage($imgIcon, $hBitmap)
  
   ; Convert File to RGB555
   ; DON'T KNOW HOW TO DO THIS :-(
  
  
   ; Insert into SQLite
   ;_SQLite_Exec($hDB, "INSERT OR REPLACE into Videos (thumbnail) VALUES ('" & $rgb555_data & "');")
  
   EndIf
  
   EndIf
  
  
WEnd
_GDIPlus_Shutdown()
_SQLite_Close()
_SQLite_Shutdown()

Func _GetImageFromDB($row)
  
  

  
EndFunc

Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16
    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

Thanks,

NiVZ

Edited by NiVZ
Posted

Better safe than sorry. Use SQLite Expert to create a new BLOB column in your table and store there the image in JPG (or PNG or whatever standard format) you want. Double check that all thumbnails get converted correctly, then only you can remove the headerless blob column. (but be sure to have a backup before: better double safe than sorry).

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

@jchd - I wish it was that easy. The database is used on a device and the images need to be in that format so the device can display them. I just want to be able to change the existing images to the ones I want :oops:

Thanks,

NiVZ

Edited by NiVZ
Posted (edited)

To convert an image to that format, you can try this:

#include<winapi.au3>
#include<sqlite.au3>
#include<windowsconstants.au3>
#include<gdiplus.au3>
_GDIPlus_Startup()

GUICreate("Test")
$imgIcon = GUICtrlCreatePic("", 10, 10, 88, 88)
GUISetState()

$hLblDC = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)

$hImg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "test.png")
$hGraph = _GDIPlus_GraphicsCreateFromHDC($hDC)

_GDIPlus_GraphicsDrawImageRect($hGraph, $hImg, 0, 0, 88, 88)
_GDIPlus_GraphicsDispose($hGraph)
_GDIPlus_ImageDispose($hImg)

$tData = DllStructCreate("byte[15488]")

$tBITMAPINFOHEADER  = DllStructCreate("DWORD biSize;LONG  biWidth;LONG  biHeight;WORD  biPlanes;WORD  biBitCount;DWORD biCompression;DWORD biSizeImage;LONG  biXPelsPerMeter;LONG  biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant; DWORD colormap[3]")
DllStructSetData($tBITMAPINFOHEADER, 1, DllStructGetSize($tBITMAPINFOHEADER))
DllStructSetData($tBITMAPINFOHEADER, 2, 88)
DllStructSetData($tBITMAPINFOHEADER, 3, -88)
DllStructSetData($tBITMAPINFOHEADER, 4, 1)
DllStructSetData($tBITMAPINFOHEADER, 5, 16)

; use default GDI32 16 bit format: 5-5-5
DllStructSetData($tBITMAPINFOHEADER,  6, 0)

; Choose Colormask manually, example for 5-5-5
;~ DllStructSetData($tBITMAPINFOHEADER,  6, 3) ;BI_BITFIELDS
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x7C00, 1) ;- Red mask
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x03E0, 2) ;- Green mask
;~ DllStructSetData($tBITMAPINFOHEADER, "colormap", 0x001F, 3) ;- Blue mask


_WinAPI_GetDIBits($hLblDC, $hBitmap, 0, 88, DllStructGetPtr($tData), DllStructGetPtr($tBITMAPINFOHEADER), 1)

_WinAPI_ReleaseDC(GUICtrlGetHandle($imgIcon), $hLblDC)
_WinAPI_DeleteDC($hDC)

_GUICtrlStatic_SetImage($imgIcon, $hBitmap)

$hFile = FileOpen(@ScriptDir & "image555.bin", 18)
FileWrite($hFile, DllStructGetData($tData, 1))
FileClose($hFile)

While GUIGetMsg()<>-3
WEnd



; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                  $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success      - 1
;                  Failure      - 0 and set @error:
;                  |1  - invalid $pSource
;                  |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc
</gdiplus.au3></windowsconstants.au3></sqlite.au3></winapi.au3>

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted (edited)

@ProgAndy - you beat me to it. I got this far, but now I can't get the data into the SQL database. It's inserting it as a readable string. I tried different combinations of Binary and Hex but not having much luck. I also saw _SQLite_Encode but I get a Syntax error in the output window when I try it.

#include<winapi.au3>
#include<sqlite.au3>
#include<windowsconstants.au3>
#include<guiconstants.au3>
#include<gdiplus.au3>
Const $DIB_RGB_COLORS = 0
$GUI    = GUICreate("Test")
$imgIcon   = GUICtrlCreatePic("", 10, 10, 88, 88)
$btnGetImage = GUICtrlCreateButton("Choose Image", 10, 100, 100, 20)
GUISetState()
$hLblDC  = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap  = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC   = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)
$hLblDC  = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))
$hBitmap  = _WinAPI_CreateCompatibleBitmap($hLblDC, 88, 88)
$hDC   = _WinAPI_CreateCompatibleDC($hLblDC)
_WinAPI_SelectObject($hDC, $hBitmap)
_GDIPlus_Startup()
_SQLite_Startup()
$hDB = _SQLite_Open(@ScriptDir & "Test.db")
Global $aRow
_SQLite_QuerySingleRow(-1, "SELECT thumbnail FROM Videos LIMIT 1", $aRow)
;$tData = DllStructCreate("byte[" & BinaryLen($aRow[0]) & "]")
$tData = DllStructCreate("byte[" & BinaryLen($aRow[0]) & "]")
DllStructSetData($tData, 1, $aRow[0])
; Bitmap Header info
$tBITMAPINFOHEADER  = DllStructCreate("DWORD biSize;LONG  biWidth;LONG  biHeight;WORD  biPlanes;WORD  biBitCount;DWORD biCompression;DWORD biSizeImage;LONG  biXPelsPerMeter;LONG  biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant; DWORD colormap[3]")
DllStructSetData($tBITMAPINFOHEADER, 1, DllStructGetSize($tBITMAPINFOHEADER))
DllStructSetData($tBITMAPINFOHEADER, 2, 88)
DllStructSetData($tBITMAPINFOHEADER, 3, -88)
DllStructSetData($tBITMAPINFOHEADER, 4, 1)
DllStructSetData($tBITMAPINFOHEADER, 5, 16)
; use default GDI32 16 bit format: 5-5-5
DllStructSetData($tBITMAPINFOHEADER,  6, 0)
_WinAPI_SetDIBits($hLblDC, $hBitmap, 0, 88, DllStructGetPtr($tData), DllStructGetPtr($tBITMAPINFOHEADER), 1)
_WinAPI_ReleaseDC(GUICtrlGetHandle($imgIcon), $hLblDC)
_WinAPI_DeleteDC($hDC)
_GUICtrlStatic_SetImage($imgIcon, $hBitmap)
While 1

   $nMsg = GuiGetMsg()

   If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop

   If $nMsg = $btnGetImage Then
   $sFilename = FileOpenDialog("Choose Image...", @DesktopDir, "Images(*.jpg;*.bmp)|All (*.*)", 3, "", $GUI)
   If @Error Then
   ; Do nothing
   Else
   $Bitmap = _GDIPlus_BitmapCreateFromFile($sFilename)
   $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
   _GUICtrlStatic_SetImage($imgIcon, $hBitmap)

  $hLblDC  = _WinAPI_GetDC(GUICtrlGetHandle($imgIcon))

   ; Convert File to RGB555
   ; DON'T KNOW HOW TO DO THIS :-(
   $oData = DllStructCreate("byte[15488]")
    
   _WinAPI_GetDIBits($hLblDC, $hBitmap, 0, 88, DllStructGetPtr($oData), DllStructGetPtr($tBITMAPINFOHEADER), 0)
   ;ConsoleWrite(DllStructGetData($oData, 1))
  
   ; Insert into SQLite
   _SQLite_Exec($hDB, "INSERT OR REPLACE into Videos (thumbnail) VALUES ('" & DllStructGetData($oData, 1) & "');")

   EndIf

   EndIf


WEnd
_GDIPlus_Shutdown()
_SQLite_Close()
_SQLite_Shutdown()
Func _GetImageFromDB($row)



EndFunc
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16
    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

Thanks,

NiVZ

Edited by NiVZ
Posted

BLOB-strings are enclosed in x'' in SQLite:

_SQLite_Exec($hDB, "INSERT OR REPLACE into Videos (thumbnail) VALUES (x'" & Hex(DllStructGetData($oData, 1)) & "');")

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

@ProgAndy - An 'x', can't believe I got so close and got stumped by an 'x' :oops:

Thanks very much with all your help with this, and you @jchd. No way I'd have figured all the image stuff out on my own.

NiVZ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...