Jump to content

Add picture to gui picture control from database field


Recommended Posts

Hi Guys,

Im writing a script that would store small thumbnail pictures into a database field and I have a specific question

on how to read the pic from the database field directly into a GUI picture control of some sort. Thanks in advance!

The code below reads a small thumbnail and stores into a database field

$jpg = FileOPen('c:\picture.jpg', 16)
$jpgfile = FileRead($jpg)

DBStore($jpgfile);Example

The code below would retrieve it from the database field and display it in

a picture control somehow. This is what I can't figure out. I am able to

read it from the dbfield and write to a jpeg picture file and the picture opens

fine. I want to skip writing it to a file just read direct from the database field

into some sort of a picture control. Any ideas? There may be some GDI method

of doing this.

-John

; example 1
#include <GUIConstants.au3>
#include <GUIConstants.au3>
GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$picbox = GUICtrlCreatePic("", 100,100,160,120,BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
$button = GUICtrlCreateButton("Read Pic",20,20,50,50)
GUISetState (@SW_SHOW)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button
            
            $ado = databaseOpen(@ScriptDir & '\PICDB.mdb')
            $searchcol = "Location"
            $searchterm = "picture1.jpg"
            $list = dbQueryLike("Pictures", $searchcol,$searchterm,1);Returns multidimensional array - dimension 6 is the field the pic thumbnail was read into.
                If IsArray($list) then
               
                $pic = Binary($list[0][6])
            
            ;GuiCtrlSetimage doesn;t work. Need to find a way to read directly from database into picture control. 
            ;Maybe GDI ??
               GUICtrlSetImage($picbox,$pic)
            Else
                Msgbox(0,"", "Not array" & $List)
            Endif
            databaseClose($ado)
    Case $GUI_EVENT_CLOSE
        EXit
    EndSwitch
Wend
Link to comment
Share on other sites

Post source of dbQueryLike()

EDIT: Also look at principles in my resource UDF: _ResourceSetImageToCtrl(), _SetBitmapToCtrl()

http://www.autoitscript.com/forum/index.php?showtopic=51103

Thanks for responding Zedna. DBQueryLike is just running a select statement retrieving the data from a field in a database. It should'nt be relevant to the problem. DBQueryLike returns an array with one element and six dimensions. Essentially one db row with six columns. The six column (dimension) is where the picdata is stored. I get the picture data by doing this:

$picbox = GUICtrlCreatePic("", 100,100,160,120,BitOR($WS_BORDER,$WS_CLIPSIBLINGS))

;$list is the array that was returned by DBQueryLike()

$pic = Binary($list[0][6]);$pic is the variable that holds the picture data as retrieved from the array, column 6.
            

;The next thing would be to send the picture to the
;picture box control. This is where your function would come in..
;but im not sure how to implement it. Help?

_ResourceSetImageToCtrl($picbox, $pic, $RT_BITMAP)

Thanks again for having a look.

John

Link to comment
Share on other sites

Try something like this:

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

$picbox = GUICtrlCreatePic("", 100,100,160,120,BitOR($WS_BORDER,$WS_CLIPSIBLINGS))

$picdata = Binary($list[0][6]);$pic is the variable that holds the picture data as retrieved from the array, column 6.
$piclength = BinaryLen($picdata)

$picstruct = DllStructCreate("byte[" & $piclength & "]", $picdata)
$picmemory = DllStructGetPtr($picstruct)

_SetMemoryImageToCtrl($picbox, $picmemory, $piclength) 

Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize) 
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc
Link to comment
Share on other sites

Not completly right, The DllStruct has to be set this way:

$picstruct = DllStructCreate("byte[" & $piclength & "]")
    DllStructSetData($picstruct,1,$picdata)
    $picmemory = DllStructGetPtr($picstruct)
    _SetMemoryImageToCtrl($picbox, $picmemory, $piclength)
    DllStructSetData($picstruct,1,0)
$picstruct = ""

*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

Link to comment
Share on other sites

Not completly right, The DllStruct has to be set this way:

$picstruct = DllStructCreate("byte[" & $piclength & "]")
    DllStructSetData($picstruct,1,$picdata)
    $picmemory = DllStructGetPtr($picstruct)
    _SetMemoryImageToCtrl($picbox, $picmemory, $piclength)
    DllStructSetData($picstruct,1,0)
$picstruct = ""
Thanks.

I will test it some day and probably I will post Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize) in Examples forum also with some simple example.

Link to comment
Share on other sites

This is a simple Example, if you want to use it :)

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

#region - GUI Create
GUICreate('Image from Stream :)',200,80,-1,-1,$WS_CAPTION+$WS_SYSMENU)
;#~ Start image Creation
$picbox = GUICtrlCreatePic("", 10,10,64,63)
GUICtrlSetCursor(-1,0)
$LOGO = _LOGOBin()
_SetImageBinaryToCtrl($picbox,$LOGO)
;#~ end image Creation
GUICtrlCreateLabel("www.progandy.de.tt",80,20)
$zedna = GUICtrlCreateLabel("Zedna on autoitscript.com",80,40)
GUICtrlSetCursor(-1,0)

GUISetState()
#endregion


#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $picbox
            ShellExecute("www.progandy.de.tt")
        Case $msg = $zedna
            ShellExecute("http://www.autoitscript.com/forum/index.php?showuser=6483")
    EndSelect
WEnd
#endregion

;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
EndFunc

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

Func _LOGOBin()
    Local $FileName = "0xFFD8FFE000104A46494600010101006000600000FFE1001645786966000049492A0008000000000000000000FFDB004300080606070605080707070909080A"
   $FileName &= "0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D"
   $FileName &= "1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC0001108003F0040"
   $FileName &= "03012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D"
   $FileName &= "01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A43444546474849"
   $FileName &= "4A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5"
   $FileName &= "C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708"
   $FileName &= "090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434"
   $FileName &= "E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A9293949596"
   $FileName &= "9798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C0301"
   $FileName &= "0002110311003F00F78DDC64D729ABF8BFEC17DF678EDE699B04E2242C703D80F7AE9657DB1393D00AE37C29FE97E30D62F32D886148978E097624FE5B17F3AF"
   $FileName &= "0B30E7AF8B8616326935776FC0EFC2538724EACD5D4509FF0009CCFF00F40CBFFF00C077FF000A07C418609116EE196DF79C2F9CA5371F6CF5AED26B88EDE332"
   $FileName &= "CD2A471AFDE791B007E2698925BDEDBEE4314F04808C821D5877E7A1A1E4CD7C35A57F52BEB343AD1D3D59574CD6ADB5240617539E7835A7BABCF759D363F0CE"
   $FileName &= "B3697DA78F2ED2EA429242B9DA8FD723B007D3B62B7B53F14DB68ED6AB7322A89D495C9C1E3AFF003ACE19855C1D4950C4FBD6D9ADC2AE0D4F96543552FBCE93"
   $FileName &= "26973EF58963E23B1BE00472A96EBD6B5C3E4023A1AF530B8FA189FE1BD7B1C5528CE93E59AB14AFE51158CAE4FF0009EB5CE780A33FD9B7D78C4E6E6E98807D"
   $FileName &= "1405AD0F13DC791A248DBB048A3C2D07D93C316119565668C48CA7A82DC915C186FDEE67567FCA923B57B9817FDE7F912F8934B9F5AD20D9413C7096914B1917"
   $FileName &= "20A8392314BE1ED1D740D256C84C653E63485F18E49CE00EC2A8EBBE25974AD4A0B1B6B2FB54D2446565DFB768CE07F5FCAB34F897C4374A63B7D262818E30F2"
   $FileName &= "316C7AF15D75B1B84A355BA92B4874B0D89A941434507AEE897C6D73E7DC69BA544D995A6F39D476400807F13FC8D5CD575CB7D2960B3BBD365BC89E2FDE9455"
   $FileName &= "70BDB1B5BAE6A9E99A47F6619F59D6EE8BCA17749349D71E83F4C0141D2F45F165F3EA16D7F72D1A9D93440B2678F978600AF1F9D7954A55B158A788A4924B45"
   $FileName &= "7EBDCE9B518C6309DDC637BB5DD95DB45D175DB77BDF0D4B1D9DF47FF2C946C5CE3EEB20E83B640FCEB47C2FAD4B705EC6F55E2BA84EC747EA0FF9FC2B92568B"
   $FileName &= "C3DE35DD64EE208A68EDA42E4B16DD8C8CFD4823E95D0EB2A2CFC71652C7F29B984EF007F75B00FE4696323FBB78986938357B7537AB4AE952936E32578DF75E"
   $FileName &= "44BE3AF35F4A448E36656E084EB8EF491F8D34C8618E34B5D480450A33067B7FBD5D21F2DD364881D7B66A3FB2D9FF00CFBA9F6AD961F1F86AB51D049A93BEE7"
   $FileName &= "9D0C4D074634EAC5E9E76392B0B93AEF8C9EF9229D2DD2258E31326D23B9F5EE6ACEADE21BEB2F16C3A6431C696ECF17CE63C9756C86FD476AD2D76EA6D22C05"
   $FileName &= "C69B6F197C82491FC3DC63D6B175FD3FFE128D32CF58D20FFA4AAE55720332F5DB9E9B95B18CFA9F5AE5C35275E756A54B3A975A5B6B1DB4E54EA4A329AB536B"
   $FileName &= "955DECFCCB1E3B9716BA7248C040D724C99E9F2A9229FE0780269771A9C9841772EF5623198C7DD3F4EB8F635969E398E583ECFA9E9624B98DB0E8CC000C3D55"
   $FileName &= "F907F95476FE3AB9B69E492F2DE17B565022821700C78FE79FD31C57A4AAE1A388559CBA5AD6D8D3EAB89FAAFB050D9EF75AFA143C3D04BE22D623B8F2CBC1F6"
   $FileName &= "937770EC721792513DCF41EC0574334DFDB3E39022F9A1B15F2B781D589CB0FC38AA5A8EBDAA7F621974ED29F4BD39884F3D940701BBAA81C0E8371F5AE83C2F"
   $FileName &= "A759E9FA6AC96E779719DDEA7D4D7062D592C253D5D4776F61D7AAE29D79AB69CA92D6DDEE69EEA37549F64B8FF9E47FEFA1FE349F64B8FF009E47FEFA1FE35F"
   $FileName &= "507CE0D611CD118661943EA3A572B2691AAF87EE64B8D25849048774903728DEFEC7DC7E39E2BADFB25C8FF9647FEFA1FE34E586ED78F2C91E8483FD6BC9C5E5"
   $FileName &= "CE753DBD0972CFF067561F172A49C5ABA7D0E324F10D9DC129AC6812E4F0488D6507078F7E94D8B5BD16CCE74DD0253213CE2D82631D0E4D766D661C1F32C816"
   $FileName &= "F5C8FF001A45B054E63B200FD56B99ACCF6718B7DCEB58BC35BE17E977638E921D7BC4E0C37282CEC5FAC49C961FED377EDD2BAAB5B48EC2C92D636CEDEBED56"
   $FileName &= "DA2BB23023DA3D148FF1A8FECB71FF003C8FFDF43FC6B7C365F515555F152BC96DD91CF88C5BA9154E2B963D91FFD9"
   Return $FileName
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

Link to comment
Share on other sites

This is a simple Example, if you want to use it <IMG src="http://www.autoitscript.com/forum/style_emoticons/autoit/smile.gif" STYLE='vertical-align: middle' emoid=":)" border="0" alt="smile.gif">

This is exactly what I would want to do.

That's GREAT.

So if you are quicker them me than you can post it in Examples forum for other people.

If you don't want to do it then I will do.

Thanks for cooperation ProgAndy!!

Link to comment
Share on other sites

*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

Link to comment
Share on other sites

I just wanted to take a moment to thank both of you for the help on this one. I wish I fully understood how it works! I have a question for either of you, hopefully a simple one. Is there a way (using GDI or some other method) to read a picture file (bmp, jpg, or gif), resize it to a thumbnail size then convert it to binary to store in the database field? Currently I am using an inefficient method to save the image to the database field. The function below creates a thumbnail and then saves it to a file. I am then reading this file into the database field, but Im sure there has to be a way to skip saving it to a file and just send the resized picture data straight to the db field. I think instead of using _GDIPlus_SaveImageToFileEx it should convert the picture data to binary so I could then save to the database. Take a look below.

CreateThumb('C:\picture.jpg', 120,160, 'C:\thumbnails\', 'picturename','jpg');this function creates a resized thumbnail of the original.

Func CreateThumb($pic, $ht, $wd, $outPath, $filename, $Ext)

 

;Start up GDIPlus

_GDIPlus_Startup ()

 

;Create canvas to put the resized image onto

$hBMP = _CreateBitmap($wd, $ht)

$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

 

;Load an image file that you want to resize

$hImage2 = _GDIPlus_ImageLoadFromFile($pic)

$hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1)

 

;Put 2nd image onto the canvas at the desired size

_GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $wd, $ht)

 

;The encoder to use for the output image

$CLSID = _GDIPlus_EncodersGetCLSID(StringUpper($Ext))

 

;Save the new image to a temporary jpeg file. I think this part can be changed to 
;save the new image straight to database rather than a file.
;I have the code in place to save to database. I just need to understand how
;to get the resized image data into binary format for sending to the database.

_GDIPlus_ImageSaveToFileEx($hImage1, $outPath & $filename & '.' & StringLower($Ext), $CLSID)


 



_GDIPlus_ImageDispose($hImage1)

_GDIPlus_ImageDispose($hImage2)

_GDIPlus_GraphicsDispose($hGraphics)

_WinAPI_DeleteObject($hBMP)

 

;Shut down GDIPlus
_GDIPlus_Shutdown()      

         

Return

EndFunc

Thanks again for all the help guys.

Regards,

John

Edited by JSunn
Link to comment
Share on other sites

I think you should try this princip (from my resources UDF):

Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0); $RT_RCDATA = 10
      Local $ResPointer, $ResSize
  
      $ResPointer = _ResourceGet($ResName, $ResType, $ResLang)
      If @error Then Return SetError(1, 0, 0)
      $ResSize = @extended
      Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer); returns struct with bytes
  EndFunc
  
  Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0); $RT_RCDATA = 10
      Local $ResStruct, $ResSize, $FileHandle

    $ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang)
If @error Then Return SetError(1, 0, 0)
$ResSize = DllStructGetSize($ResStruct)

        If $CreatePath Then $CreatePath = 8; mode 8 = Create directory structure if it doesn't exist
    $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
    If @error Then Return SetError(2, 0, 0)
    FileWrite($FileHandle, DllStructGetData($ResStruct, 1))
    If @error Then Return SetError(3, 0, 0)
    FileClose($FileHandle)
    If @error Then Return SetError(4, 0, 0)

    Return $ResSize
EndFunc

princip is to create structure "over" your memory (hBitmap?)

$struct = DllStructCreate("byte[" & $MemSize & "]", $MemPointer)

and then get binary data by 

$data = DllStructGetData($struct, 1)
Link to comment
Share on other sites

I think you should try this princip (from my resources UDF):

Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0); $RT_RCDATA = 10
      Local $ResPointer, $ResSize
  
      $ResPointer = _ResourceGet($ResName, $ResType, $ResLang)
      If @error Then Return SetError(1, 0, 0)
      $ResSize = @extended
      Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer); returns struct with bytes
  EndFunc
  
  Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0); $RT_RCDATA = 10
      Local $ResStruct, $ResSize, $FileHandle

    $ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang)
If @error Then Return SetError(1, 0, 0)
$ResSize = DllStructGetSize($ResStruct)

        If $CreatePath Then $CreatePath = 8; mode 8 = Create directory structure if it doesn't exist
    $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
    If @error Then Return SetError(2, 0, 0)
    FileWrite($FileHandle, DllStructGetData($ResStruct, 1))
    If @error Then Return SetError(3, 0, 0)
    FileClose($FileHandle)
    If @error Then Return SetError(4, 0, 0)

    Return $ResSize
EndFunc

princip is to create structure "over" your memory (hBitmap?)

$struct = DllStructCreate("byte[" & $MemSize & "]", $MemPointer)

and then get binary data by

$data = DllStructGetData($struct, 1)

Well, Ive had a look at your example and I can't say I have a clue about how to implement it. I think its safe to say I'm pretty much lost. My knowledge of C/C++ along with DLLStructCreate / DLLCall etc. is non-existent although I would like to learn. Let me say thanks again for the help..

Here is what I changed it to, needless to say it doesn't work:

#include <Resources.au3>


Func CreateThumb($pic, $ht, $wd, $outPath, $filename, $Ext)

 
;Start up GDIPlus
_GDIPlus_Startup ()

 

;Create canvas to put the resized image onto
$hBMP = _CreateBitmap($wd, $ht)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

 

;Load an image file that you want to resize
$hImage2 = _GDIPlus_ImageLoadFromFile($pic)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1)

 

;Put 2nd image onto the canvas at the desired size
_GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $wd, $ht)

 

;The encoder to use for the output image
$CLSID = _GDIPlus_EncodersGetCLSID(StringUpper($Ext))

 
;Convert the resized image to binary data.
$binarydata  = _ResourceGetAsBytes($hImage1); $RT_RCDATA = 10$hImage1

;No longer using this to save to file
;_GDIPlus_ImageSaveToFileEx($hImage1, $outPath & $filename & '.' & StringLower($Ext), $CLSID)


;Save binary data (string) to database field (Example only)
DBAddRecord($tablename, $fieldname, $binarydata)

 
;Clean up resources
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_DeleteObject($hBMP)

 

;Shut down GDIPlus
_GDIPlus_Shutdown()      

         

Return
Link to comment
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
 Share

  • Recently Browsing   0 members

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