Jump to content
Zoldex

Load a picture, resize, show in a gui and store in SQLite

Recommended Posts

Zoldex

As the title says, I'm trying to show a thumbnail in a gui, selected by the user, which must be resized to fit the Gui Control and store the image itself in SQLite as a blob.

Thanks to some useful examples found on the forum, I managed to load, show and store an image but I'm experiencing some problems in resizing the picture.

This is what i made until now:

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


Local $hGUI, $hBMP, $hBitmap, $hGraphic
Local $hQuery, $item
Local $filename
Local $x = 100, $y = 100

_SQLite_Startup()
_SQLite_Open() ; open Database in Memory
If @error Then
MsgBox(16, "SQLite Error", "Can't Load Database!")
Exit -1
EndIf

_SQLite_Exec(-1,"CREATE TABLE IF NOT EXISTS DBTest (IMAGE BLOB);")


$hGUI = GUICreate("GUI", 400, 300)

$GUIImage = GUICtrlCreatePic("", 10, 10, $x, $y, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$SS_SUNKEN,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUISetState()

GUISetState(@SW_SHOW)


Local $filename = FileOpenDialog("Select image",@ScriptDir,"Image (*.jpg;*.bmp)",3)

; I could show the image in the gui here:
; GUICtrlSetImage($GUIImage,$ImageFileName)
; But I want to resize it, store it in a DB, then show the resized image in the GUI

; This is what I am trying to do for resize (taken from an example made by UEZ):
_GDIPlus_Startup()
Local $hImageFromFile = _GDIPlus_ImageLoadFromFile($filename)
Local $Thumbnail = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "handle", $hImageFromFile, "uint", $x, "uint", $y, "int*", 0, "ptr", 0, "ptr", 0)
$Thumbnail = $Thumbnail[4]

$object_bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Thumbnail); Create a Bitmap object from a bitmap handle (?)
_GDIPlus_Shutdown()

;********** How could I show the resized pic in the GUI? Dunno :( *****

;preparing resized image for storing in SQLite
Local $binary_bitmap = Binary($object_bitmap)
Local $encoded_bitmap = _SQLite_FastEncode($binary_bitmap)

;insert the blob
If Not _SQLite_Exec(-1, "SELECT IMAGE FROM DBTest") = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO DBTest (IMAGE) VALUES (" & $encoded_bitmap & ");") = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg())

;Retrieve from database
If Not _SQLite_Query(-1, "SELECT * FROM DBTest;", $hQuery) = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_FetchData($hQuery, $item, False, False) = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg())

Local $retrieve_pic = $item[0]

;NOW *I THINK* I SHOULD HAVE THE RESIZED PICTURE IN $retrieve_pic BUT I CAN'T SHOW IT IN THE GUI.....


; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

_SQLite_Close()
_SQLite_Shutdown()
Exit

I'm not very good at GDI coding and quite a newbie with SQLite, too...

Any help would be very appreciated!

Share this post


Link to post
Share on other sites
jchd

I don't know much about graphics and leave that part of the question to others.

About the SQLite part I can give you a few advices.

After _SQLite_Query and _SQLite_FetchData you should use _SQLite_Finalize to finalize the query (destroy the query object internal to SQLite you've created). Better yet, instead of using that 3-step sequence, use _SQLite_GetTable, _SQLiteGetTable2d or _SQLite_QuerySingleRow. These calls are much simpler and handle errors correctly.

Also I don't think that storing the resized bitmap in the DB is a good idea. Should your GUI change, you'll have to resize it (up or down) to fit the new control size. Then there is a difference in format between storing a copy of the image file (e.g. in .bmp or .png or .jpg format) and a windows bitmap, resized or not. Finally it's better to store the image in .jpg format as a separate file and only store the relative path in the DB.


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)

Share this post


Link to post
Share on other sites
dany

About displaying the thumbnail:

Global Const $IMAGE_BITMAP = 0 ; Needed for GUICtrlSendMsg.
Global Const $STM_SETIMAGE = 0x0172 ; Needed for GUICtrlSendMsg.

Global $hPic = GUICtrlCreatePic('', 0, 0, 100, 100) ; Picture control, adjust size if required.

; I don't think this line is necessary, it's the HBITMAP handle you need.
;$object_bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Thumbnail); Create a Bitmap object from a bitmap handle (?)

; GDIPlus already includes WinAPI.
_WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $Thumbnail)) ; Set the thumbnail to the Pic control.
; clean up routine here.

So you don't have to fetch a blob from your database, that's just overcomplicating things. You already have the image so why fetch it?

Also, I second what jchd says. Store the relative path in your database and not the image itself.


[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
Share on other sites
UEZ

You can try to use these 2 functions to scale the image, save it as a binary string (JPG) and store it in the DB.

#include <GDIPlus.au3>
#include <Memory.au3>

_GDIPlus_Startup()
Global $sFile = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUImsoobe.jpg")
Global $hBitmap  = _GDIPlus_ScaleImage($sFile, 102, 76)
Global $bImage = _GDIPlus_SaveImage2Binary($hBitmap)
MsgBox(0, "Binary", $bImage)
_GDIPlus_Shutdown()

Func _GDIPlus_SaveImage2Binary($hBitmap, $iQuality = 50) ;coded by Andreik, modified by UEZ
    Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg")
    Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
    Local $pEncoder = DllStructGetPtr($tGUID)
    Local $tParams = _GDIPlus_ParamInit (1)
    Local $tData = DllStructCreate("int Quality")
    DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
    Local $pData = DllStructGetPtr($tData)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
    Local $pParams = DllStructGetPtr($tParams)
    Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    $hStream = $hStream[3]
    DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    $hMemory = $hMemory[2]
    Local $iMemSize = _MemGlobalSize($hMemory)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr")
    Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
    _MemGlobalFree($hMemory)
    Return $bData
EndFunc


Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012
    If Not FileExists($sFile) Then Return SetError(1, 0, 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    If @error Then Return SetError(2, 0, 0)
    Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    If @error Then Return SetError(3, 0, 0)
    $hBitmap = $hBitmap[6]
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hBmpCtxt)
    Return $hBitmap
EndFunc

Br,

UEZ

Edited by UEZ
  • Like 1

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
Zoldex

About displaying the thumbnail:

Global Const $IMAGE_BITMAP = 0 ; Needed for GUICtrlSendMsg.
Global Const $STM_SETIMAGE = 0x0172 ; Needed for GUICtrlSendMsg.

Global $hPic = GUICtrlCreatePic('', 0, 0, 100, 100) ; Picture control, adjust size if required.

; I don't think this line is necessary, it's the HBITMAP handle you need.
;$object_bitmap = _GDIPlus_BitmapCreateFromHBITMAP($Thumbnail); Create a Bitmap object from a bitmap handle (?)

; GDIPlus already includes WinAPI.
_WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $Thumbnail)) ; Set the thumbnail to the Pic control.
; clean up routine here.

So you don't have to fetch a blob from your database, that's just overcomplicating things. You already have the image so why fetch it?

Also, I second what jchd says. Store the relative path in your database and not the image itself.

I do prefer to store images in DB because there will be a relatively small number of records (Max 1000) and need a single .db file.

So I need to retrieve the image from DB, eventually resize it, and show in the pic control

Anyways, still I can't display the image in the pic control...

What am I wrong in? :huh2:

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Memory.au3>


Global Const $IMAGE_BITMAP = 0 ; Needed for GUICtrlSendMsg.
Global Const $STM_SETIMAGE = 0x0172 ; Needed for GUICtrlSendMsg.

Local $hGUI, $hBMP, $hBitmap, $hGraphic
Local $hQuery, $item
Local $filename
Local $x = 100, $y = 100

_SQLite_Startup()
_SQLite_Open() ; open Database in Memory
If @error Then
MsgBox(16, "SQLite Error", "Can't Load Database!")
Exit -1
EndIf

_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS DBTest (IMAGE BLOB);")


$hGUI = GUICreate("GUI", 400, 300)

$GUIImage = GUICtrlCreatePic("", 40, 40, $x, $y, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
;$button1 = GUICtrlCreateButton("1",10,10)
;$button2 = GUICtrlCreateButton("2",50,10)
;GUISetState()

GUISetState(@SW_SHOW)


Local $filename = FileOpenDialog("Select image", @ScriptDir, "Image (*.jpg;*.bmp)", 3)

_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_ScaleImage($filename, $x, $y)
Global $bImage = _GDIPlus_SaveImage2Binary($hBitmap)
MsgBox(0, "Binary", $bImage)


_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $bImage)) ; Does not seems to work
;_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) ; Also tried this with no luck

_GDIPlus_Shutdown()


; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

_SQLite_Close()
_SQLite_Shutdown()
Exit

Func _GDIPlus_SaveImage2Binary($hBitmap, $iQuality = 50) ;coded by Andreik, modified by UEZ
Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg")
Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
Local $pEncoder = DllStructGetPtr($tGUID)
Local $tParams = _GDIPlus_ParamInit (1)
Local $tData = DllStructCreate("int Quality")
DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
Local $pData = DllStructGetPtr($tData)
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
Local $pParams = DllStructGetPtr($tParams)
Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
$hStream = $hStream[3]
DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams)
_GDIPlus_BitmapDispose($hBitmap)
Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
$hMemory = $hMemory[2]
Local $iMemSize = _MemGlobalSize($hMemory)
Local $pMem = _MemGlobalLock($hMemory)
$tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
Local $bData = DllStructGetData($tData, 1)
Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr")
Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
_MemGlobalFree($hMemory)
Return $bData
EndFunc


Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012
If Not FileExists($sFile) Then Return SetError(1, 0, 0)
Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If @error Then Return SetError(2, 0, 0)
Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(3, 0, 0)
$hBitmap = $hBitmap[6]
Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
_GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hBmpCtxt)
Return $hBitmap
EndFunc

Share this post


Link to post
Share on other sites
UEZ

You need to convert the GDI+ bitmap to a WinAPI bitmap format.

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Memory.au3>


Global Const $IMAGE_BITMAP = 0 ; Needed for GUICtrlSendMsg.
Global Const $STM_SETIMAGE = 0x0172 ; Needed for GUICtrlSendMsg.

Local $hGUI, $hBMP, $hBitmap, $hGraphic
Local $hQuery, $item
Local $filename
Local $x = 100, $y = 100

_SQLite_Startup()
_SQLite_Open() ; open Database in Memory
If @error Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit -1
EndIf

_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS DBTest (IMAGE BLOB);")


$hGUI = GUICreate("GUI", 400, 300)

$GUIImage = GUICtrlCreatePic("", 40, 40, $x, $y, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
;$button1 = GUICtrlCreateButton("1",10,10)
;$button2 = GUICtrlCreateButton("2",50,10)
;GUISetState()

GUISetState(@SW_SHOW)


Local $filename = FileOpenDialog("Select image", @ScriptDir, "Image (*.jpg;*.bmp)", 3)

_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_ScaleImage($filename, $x, $y)
Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

Global $bImage = _GDIPlus_SaveImage2BinaryString($hBitmap)
;~ MsgBox(0, "Binary", $bImage)

_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) ; Does not seems to work
;_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) ; Also tried this with no luck
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

_SQLite_Close()
_SQLite_Shutdown()
Exit

Func _GDIPlus_SaveImage2BinaryString($hBitmap, $iQuality = 50, $bSave = False, $sFilename = "Converted.jpg") ;coded by Andreik, modified by UEZ
    Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg")
    Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
    Local $pEncoder = DllStructGetPtr($tGUID)
    Local $tParams = _GDIPlus_ParamInit(1)
    Local $tData = DllStructCreate("int Quality")
    DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
    Local $pData = DllStructGetPtr($tData)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
    Local $pParams = DllStructGetPtr($tParams)
    Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(1, 0, 0)
    $hStream = $hStream[3]
    DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(2, 0, 0)
    $hMemory = $hMemory[2]
    Local $iMemSize = _MemGlobalSize($hMemory)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr")
    Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
    _MemGlobalFree($hMemory)
    If $bSave Then
        Local $hFile = FileOpen(@ScriptDir & "" & $sFilename, 18)
        FileWrite($hFile, $bData)
        FileClose($hFile)
    EndIf
    Return $bData
EndFunc   ;==>_GDIPlus_SaveImage2BinaryString


Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012
    If Not FileExists($sFile) Then Return SetError(1, 0, 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    If @error Then Return SetError(2, 0, 0)
    Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    If @error Then Return SetError(3, 0, 0)
    $hBitmap = $hBitmap[6]
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hBmpCtxt)
    Return $hBitmap
EndFunc   ;==>_GDIPlus_ScaleImage

Br,

UEZ

Edited by UEZ
  • Like 1

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
Zoldex

You need to convert the GDI+ bitmap to a WinAPI bitmap format.

GREAT!

That shows my knowledge level about GDI+ and WinAPI: near ZERO :

Thanks to you guys now I can:

Resize the image (by UEZ)

Global $hBitmap = _GDIPlus_ScaleImage($filename, $x, $y)

Update the pic control (by UEZ / Andy)

Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($GUIImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))

Convert the image in binary to store in SQLite (by UEZ)

Global $bImage = _GDIPlus_SaveImage2Binary($hBitmap)

Now I miss a way to convert the image back from binary to update the pic control after fetching DB

How could I do?

Share this post


Link to post
Share on other sites
UEZ

To convert the binary image (JPG) back to a bitmap structure you can use the _GDIPlus_BMPFromMemory() (formerly Load_BMP_From_Mem) function.

See 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
Zoldex

To convert the binary image (JPG) back to a bitmap structure you can use the _GDIPlus_BMPFromMemory() (formerly Load_BMP_From_Mem) function.

See here:

Br,

UEZ

I'm delighted. Really.

I wouldn't abuse of your time, but I would love to let the user choose an (rectangular) area of the selected picture to crop, but I really don't have idea where to begin...

Edited by Zoldex

Share this post


Link to post
Share on other sites
x_bennY

I'm on a project that needs to store 3000 images in a single file, i think this will help, i'm trying to run the script but i'm getting this error:

"SQLite Error", "Can't Load Database!"

@error:  3 - _SQLite_Startup() not yet called

Tryied to put the dlls(SQLite3.dll and SQLite3_x64.dll) on the native folder, but didnt work.

 

Edited by x_bennY

Share this post


Link to post
Share on other sites
jchd

Post your code.

 


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)

Share this post


Link to post
Share on other sites
x_bennY

hey! i used the code posted here by UEZ!

Share this post


Link to post
Share on other sites
Skysnake

Do you have a SQLite DLL in your folder?

Edited by Skysnake

Skysnake

Why is the snake in the sky?

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

  • Similar Content

    • dangr82
      By dangr82
       
      I have created this function for a database, but I can not make it work. I always have two error messages: "not an error" ... and the file created, in the script directory, does not contain anything.
      Global $sDBName = "Hen.db" Func DatabaseTable() Local $sConnDB _SQLite_Startup() If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf $sConnDB = _SQLite_Open($sDBName) If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!") Exit -1 EndIf If Not _SQLite_Exec($sDBName, 'CREATE TABLE Animal ("Name", "Age");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec($sDBName, 'INSERT INTO Animale VALUES ("Charlie","5");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) _SQLite_Close($sConnDB) _SQLite_Shutdown() EndFunc  
    • Eminence
      By Eminence
      Hello,
      I've been searching on how to select the first row in my database which includes a time column based on the latest start_time date for today's date.
      This is my current code:
      Local $iCurrentDate = _Now() Local $sqlHandle = _dbOpen($sDbPath) Local $aResult, $iRows, $iCols _SQLite_GetTable2d($sqlHandle, "SELECT start_time FROM " & $srawDb & " ORDER BY datetime(start_time) DESC LIMIT 1", $aResult, $iRows, $iCols) _ArrayDisplay($aResult) _dbClose($sDbpath) What it does is it gets the first row entry in the database however it does not select the latest start_time entry in the database, it always select the first row. I've tried changing DESC to ASC to see if that will do it but the issue still remains. Any thoughts on this? Thanks in advance.
       
      *EDIT
      The date format in the database is by MM/DD/YYYY HH:MM:SS.
    • Seminko
      By Seminko
      In my recent project I'm downloading a bunch of data, so I decided to store it in a SQLite database. NOTE: I'm using sqlite3_x64.dll
      Everything is working just fine but I'm struggling with getting the Median value. SQLite has an Average function but not a Median one.
      I googled but all of the provided solutions are way above my pay-grade. After some more searching I found 'extension-functions.c' on the SQLite site where Median is included. After almost an hour of struggling I was able to successfully compile it into a DLL.
      So I downloaded @jchd's SQLiteExtLoad.au3 as seen here:
      But I'm getting these errors:
      "Path\SQLiteExtLoad.au3"(21,40) : warning: $g_hDll_SQLite: possibly used before declaration. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "Path\SQLiteExtLoad.au3"(21,40) : error: $g_hDll_SQLite: undeclared global variable. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ So I tried, copying the function to my file and changing the DLL variable ($g_hDll_SQLite) directly to the DLL location (C:\...\.. .dll), but now this error fires
      If __SQLite_hChk($hConn, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) To be honest, I don't know what to use as the $hConn - handle of connection.
      I would appreciate any help, be it getting the median using SQLite queries or getting the DLL extension loaded using AutoIt.
      Thanks, S.
       
      EDIT: well, I suspect the $hConn variable refers to the return value of the _SQLite_Open function. Well, at least now _SQLite_EnableExtensions doesn't give errors. Now I run into problems with _SQLite_LoadExtension, which gives error -1, and extended 1. Apparently the 1 constant is a generic error where other error do not apply.
      BTW, anybody knows whether I need to compile the extension DLL "into" x64 when I use a x64 SQLite? That might be the problem...
       
      EDIT2: I recompiled the dll and tried it using the SQLite3.exe and it works, so I'm confident the extension DLL has been created correctly

    • Ascer
      By Ascer
      Hello,
      Do you have any idea to resize Vector graphic using some maths trick?
      It's example to create Vector image 10x10px and write A
      Local $a10x10 = [ _ 1,1,1,1,1,1,1,1,1,1, _ 1,1,1,0,0,0,0,1,1,1, _ 1,1,0,0,1,1,0,0,1,1, _ 1,1,0,1,1,1,1,0,1,1, _ 1,1,0,1,1,1,1,0,1,1, _ 1,1,0,0,0,0,0,0,1,1, _ 1,1,0,1,1,1,1,0,1,1, _ 1,1,0,1,1,1,1,0,1,1, _ 1,0,0,0,1,1,0,0,0,1, _ 1,1,1,1,1,1,1,1,1,1 _ ] Local $oVector = ObjCreate("WIA.Vector.1") If Not IsObj($oVector) Then ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF) Exit EndIf Local $iBlue = 0xFF0000FF ; ARGB color Local $iWhite = 0xFFFFFFFF ; adding pixels to vector For $i = 0 To UBound($a10x10) - 1 Local $iPixel = $a10x10[$i] Local $iColor = $iBlue If $iPixel = 0 Then $iColor = $iWhite $oVector.Add($iColor) Next ; create a img 10x10 px Local $oImg = $oVector.ImageFile(10, 10) ; path to file Local $sPath = @ScriptDir & "\Vector.bmp" ; delete previous file if exits. FileDelete($sPath) ; save img to script direction. $oImg.SaveFile($sPath) ; show result, you have to use 800% size to see effects. ShellExecute("Vector.bmp")  
    • AdamUL
      By AdamUL
      I have been testing AutoIt 3.3.14.3 with SQLite, and the Help File examples.  The examples that I have tested are throwing errors or not doing anything.  I have sqlite3.dll, sqlite3_x64.dll, and sqlite3.exe in the directories with the testing script.  I am copying the examples directly from the help file into a test script for testing with no edits.  The _SQLite_GetTable2d example is returning an error ("Library used incorrectly") with each _SQLite_Exec command.  The _SQLite_FastEncode example returns an empty dialog box.  The _SQLite_Exec example only prints out the SQLite version, and nothing else in the SciTE console.  Currently, I'm still searching for what is causing this issue.  I'm on Windows 7 Enterprise 64-bit.  Is anyone else having this issue?  
       
      Adam
       
×