Jump to content

[SOLVED] Convert Bitmap image to JPG in memory


Recommended Posts

Hey

I'm not really familliar with GDI Plus , I am looking for how tocConvert a bitmap image to JPG in memory without saving it to disk

Because I want to send it later via TCP directly without using FileRead and other stuff ..

The only function I found is below but it saves the image in disk :(

Func SaveBmp2JPG($Bitmap, $sSave = "Converted.jpg", $iQuality = 20) ;coded by UEZ 2013
    If Not IsPtr($Bitmap) Then
        $Bitmap = _GDIPlus_ImageLoadFromFile($sFile)
        If @error Then Return SetError(1, 0, 0)
    EndIf
    Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $tParams = _GDIPlus_ParamInit(1)
    Local $tData = DllStructCreate("int Quality")
    Local $pData = DllStructGetPtr($tData)
    Local $pParams = DllStructGetPtr($tParams)
    DllStructSetData($tData, "Quality", $iQuality)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
    If Not _GDIPlus_ImageSaveToFileEx($Bitmap, $sSave, $sCLSID, $pParams) Then Return SetError(2, 0, 0)
    Return True
EndFunc

what my code now looks like :

#include <ScreenCapture.au3>
#include <guiconstantsex.au3>
#include <gdiplus.au3>
#include <memory.au3>
#include <staticconstants.au3>


Global $ghGDIPDLL = $__g_hGDIPDll

 Example()
Func Example()

    _GDIPlus_Startup()
    Local $hHBmp = _ScreenCapture_Capture("") ;create a GDI bitmap by capturing my desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
    Local $hBitmap_Scaled2 = _GDIPlus_ImageResize($hBitmap,  @DesktopWidth / 1.5, @DesktopHeight / 1.5) ;resize image

SaveBmp2JPG($hBitmap_Scaled2,'Test.jpg',99) ; ===> Saving to disk ??


    _GDIPlus_Shutdown()

EndFunc   ;==>Example

Func SaveBmp2JPG($Bitmap, $sSave , $iQuality) ;coded by UEZ 2013
    If Not IsPtr($Bitmap) Then
        $Bitmap = _GDIPlus_ImageLoadFromFile($sFile)
        If @error Then Return SetError(1, 0, 0)
    EndIf
    Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $tParams = _GDIPlus_ParamInit(1)
    Local $tData = DllStructCreate("int Quality")
    Local $pData = DllStructGetPtr($tData)
    Local $pParams = DllStructGetPtr($tParams)
    DllStructSetData($tData, "Quality", $iQuality)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
   If Not _GDIPlus_ImageSaveToFileEx($Bitmap, $sSave, $sCLSID, $pParams) Then Return SetError(2, 0, 0)
    Return True
 EndFunc

 

Edited by DrAhmed
Link to comment
Share on other sites

Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFilename = "Converted.jpg") ;coded by UEZ 2013 build 2013-09-14
    Local $sImgCLSID, $tGUID, $tParams
    Switch $sFormat
        Case "JPG"
            $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
            $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
            Local $pData = DllStructGetPtr($tData)
            $tParams = _GDIPlus_ParamInit(1)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
        Case "PNG", "BMP", "GIF", "TIF"
            $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
            $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(2, 0, 0)
    _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
    If @error Then Return SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(4, 0, 0)
    Local $iMemSize = _MemGlobalSize($hMemory)
    If Not $iMemSize Then Return SetError(5, 0, 0)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
    _MemGlobalFree($hMemory)
    If $bSave Then
        Local $hFile = FileOpen($sFilename, 18)
        If @error Then Return SetError(6, 0, $bData)
        FileWrite($hFile, $bData)
        FileClose($hFile)
    EndIf
    Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString

It's a hard function to find on the forums, so I have it saved on my computer.

Link to comment
Share on other sites

9 hours ago, InunoTaishou said:
Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFilename = "Converted.jpg") ;coded by UEZ 2013 build 2013-09-14
    Local $sImgCLSID, $tGUID, $tParams
    Switch $sFormat
        Case "JPG"
            $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
            $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
            Local $pData = DllStructGetPtr($tData)
            $tParams = _GDIPlus_ParamInit(1)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
        Case "PNG", "BMP", "GIF", "TIF"
            $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
            $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(2, 0, 0)
    _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
    If @error Then Return SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(4, 0, 0)
    Local $iMemSize = _MemGlobalSize($hMemory)
    If Not $iMemSize Then Return SetError(5, 0, 0)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx
    _MemGlobalFree($hMemory)
    If $bSave Then
        Local $hFile = FileOpen($sFilename, 18)
        If @error Then Return SetError(6, 0, $bData)
        FileWrite($hFile, $bData)
        FileClose($hFile)
    EndIf
    Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString

It's a hard function to find on the forums, so I have it saved on my computer.

Thanks man but I don't think it's working :( , I tried to save the result image on hdd to debug and the filesize was 8kb with empty image .

Link to comment
Share on other sites

And here I could not even put the functions WinAPI CreateStreamOnHGlobal() , _WinAPI_GetHGlobalFromStream() and _WinAPI_ReleaseStream() in the script!

Link to comment
Share on other sites

@DrAhmed: Search the forum for "_GDIPlus_StreamImage2BinaryString" and you will find several examples how to use it in different scenarios.

You even replied here:

 

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

6 minutes ago, UEZ said:

@DrAhmed: Search the forum for "_GDIPlus_StreamImage2BinaryString" and you will find several examples how to use it in different scenarios.

You even replied here:

 

 

My bad , I feel so stupid , I used it wrong .. works like charm thanks man. You are the best B) . 

Link to comment
Share on other sites

If the memory consumption of your script is permanetely increasing then you have probably a memory leak. This mostly occurs when you don't release GDI/GDI+ resources.

Btw, define "high usage". What is the size of your images which you send to this function?

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ

The image size is really small arround 50KB , I set a low value for JPG quality and used image resize to reduce it .

that's what I am getting after few seconds of running the script :

Rp1y3tE.jpg

 

Edit : I am using this func to encode the stream data before sending them , can it be the reason ?

; #FUNCTION# ;===============================================================================
;
; Name...........: _Base64Encode
; Description ...: Returns the given strinng encoded as a Base64 string.
; Syntax.........: _Base64Encode($sData)
; Parameters ....: $sData
; Return values .: Success - Base64 encoded string.
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - Could not create DOMDocument
;                  |2 - Could not create Element
;                  |3 - No string to return
; Author ........: turbov21
; Modified.......:
; Remarks .......:
; Related .......: _Base64Decode
; Link ..........;
; Example .......; Yes
;
; ;==========================================================================================
Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc   ;==>_Base64Encode

 

Edited by DrAhmed
Link to comment
Share on other sites

Are you calling the function in a loop or only one time? Is the memory consumption just high or is it increasing permanetely?

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

17 minutes ago, UEZ said:

Are you calling the function in a loop or only one time? Is the memory consumption just high or is it increasing permanetely?

1- In a loop ( but I set the sleep(1000) )

2-   Increasing permanetely

Link to comment
Share on other sites

Ok, then you doing something wrong in your loop as mentioned in post #8.

Show me that loop please.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

28 minutes ago, UEZ said:

Ok, then you doing something wrong in your loop as mentioned in post #8.

Show me that loop please.

Sure :

#include <gdiplus.au3>
#include <memory.au3>
#include <staticconstants.au3>


Global $ghGDIPDLL = $__g_hGDIPDll

While 1
    
  $data = Desk_Stream(50)
  
  
  ; Here I use TCPSend to send the data to my client
   
   Sleep(1000)
WEnd

Func Desk_Stream($Q)
    _GDIPlus_Startup()
    


    Local $hHBmp = _ScreenCapture_Capture("") ;create a GDI bitmap by capturing my desktop

   Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap


Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap,  @DesktopWidth / 12, @DesktopHeight / 1.2) ;resize image

    $sB64 = _Base64Encode( _GDIPlus_StreamImage2BinaryString($hBitmap_Scaled,$sQ, False, '')) ;coded by UEZ 2013 build 2014-01-25; based on the code
    

  _GDIPlus_Shutdown()

Return $sB64
EndFunc   ;==>Example



Func _GDIPlus_StreamImage2BinaryString($hBitmap, $iQuality , $bSave, $sFilename ) ;coded by UEZ 2013 build 2014-01-25; based on the code by Andreik
    Local $sImgCLSID, $tGUID, $tParams, $tData
     $sFormat = "JPG"

            $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
            $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
            $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
            Local $pData = DllStructGetPtr($tData)
            $tParams = _GDIPlus_ParamInit(1)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
                

    Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(2, 0, 0)
    _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
    If @error Then Return SetError(3, 0, 0)

    Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(4, 0, 0)
    Local $iMemSize = _MemGlobalSize($hMemory)
    If Not $iMemSize Then Return SetError(5, 0, 0)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
   _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx

    _MemGlobalFree($hMemory)
    
    Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString

Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc   ;==>_Base64Encode

 

Edited by DrAhmed
Link to comment
Share on other sites

As I said above you have to release the resources!

Do something like this here:

#include <gdiplus.au3>
#include <memory.au3>
#include <staticconstants.au3>

_GDIPlus_Startup()

Global $ghGDIPDLL = $__g_hGDIPDll

While 1

    $data = Desk_Stream(50)


    ; Here I use TCPSend to send the data to my client

    Sleep(1000)
WEnd

_GDIPlus_Shutdown()



Func Desk_Stream($Q)

    Local $hHBmp = _ScreenCapture_Capture("") ;create a GDI bitmap by capturing my desktop

    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap

    Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, @DesktopWidth / 12, @DesktopHeight / 1.2) ;resize image

    $sB64 = _Base64Encode(_GDIPlus_StreamImage2BinaryString($hBitmap_Scaled, $sQ, False, '')) ;coded by UEZ 2013 build 2014-01-25; based on the code

    ;release resources otherwise memory leak
    _WinAPI_DeleteObject($hHBmp)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_ImageDispose($hBitmap_Scaled)
    

    Return $sB64
EndFunc   ;==>Desk_Stream



Func _GDIPlus_StreamImage2BinaryString($hBitmap, $iQuality, $bSave, $sFilename) ;coded by UEZ 2013 build 2014-01-25; based on the code by Andreik
    Local $sImgCLSID, $tGUID, $tParams, $tData
    $sFormat = "JPG"

    $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
    $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
    $tData = DllStructCreate("int Quality")
    DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
    Local $pData = DllStructGetPtr($tData)
    $tParams = _GDIPlus_ParamInit(1)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)


    Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(2, 0, 0)
    _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
    If @error Then Return SetError(3, 0, 0)

    Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(4, 0, 0)
    Local $iMemSize = _MemGlobalSize($hMemory)
    If Not $iMemSize Then Return SetError(5, 0, 0)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx

    _MemGlobalFree($hMemory)

    Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString

Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc   ;==>_Base64Encode

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

16 minutes ago, UEZ said:

As I said above you have to release the resources!

Do something like this here:

#include <gdiplus.au3>
#include <memory.au3>
#include <staticconstants.au3>

_GDIPlus_Startup()

Global $ghGDIPDLL = $__g_hGDIPDll

While 1

    $data = Desk_Stream(50)


    ; Here I use TCPSend to send the data to my client

    Sleep(1000)
WEnd

_GDIPlus_Shutdown()



Func Desk_Stream($Q)

    Local $hHBmp = _ScreenCapture_Capture("") ;create a GDI bitmap by capturing my desktop

    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap

    Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, @DesktopWidth / 12, @DesktopHeight / 1.2) ;resize image

    $sB64 = _Base64Encode(_GDIPlus_StreamImage2BinaryString($hBitmap_Scaled, $sQ, False, '')) ;coded by UEZ 2013 build 2014-01-25; based on the code

    ;release resources otherwise memory leak
    _WinAPI_DeleteObject($hHBmp)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_ImageDispose($hBitmap_Scaled)
    

    Return $sB64
EndFunc   ;==>Desk_Stream



Func _GDIPlus_StreamImage2BinaryString($hBitmap, $iQuality, $bSave, $sFilename) ;coded by UEZ 2013 build 2014-01-25; based on the code by Andreik
    Local $sImgCLSID, $tGUID, $tParams, $tData
    $sFormat = "JPG"

    $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat)
    $tGUID = _WinAPI_GUIDFromString($sImgCLSID)
    $tData = DllStructCreate("int Quality")
    DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100
    Local $pData = DllStructGetPtr($tData)
    $tParams = _GDIPlus_ParamInit(1)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)


    Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx
    If @error Then Return SetError(2, 0, 0)
    _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams))
    If @error Then Return SetError(3, 0, 0)

    Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx
    If @error Then Return SetError(4, 0, 0)
    Local $iMemSize = _MemGlobalSize($hMemory)
    If Not $iMemSize Then Return SetError(5, 0, 0)
    Local $pMem = _MemGlobalLock($hMemory)
    $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem)
    Local $bData = DllStructGetData($tData, 1)
    _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx

    _MemGlobalFree($hMemory)

    Return $bData
EndFunc   ;==>_GDIPlus_StreamImage2BinaryString

Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc   ;==>_Base64Encode

 

Wow , thanks it fixed RAM usage but CPU Usage still high ( Between 6-12 )

Link to comment
Share on other sites

6-12% is not that high but for Sleep(1000) it is.

 

I don't know what code is behind 

; Here I use TCPSend to send the data to my client

Have a look there.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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

×
×
  • Create New...