Jump to content

[Solved] Get stream size


Recommended Posts

Hey

I was looking for methode to get the stream size of a picture from memory , wihtout need to write stream data to disk the then use filegetsize 

Thats what I am trying to do

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

_GDIPlus_Startup()

Global $ghGDIPDLL = $__g_hGDIPDll

While 1

$data = Desk_Stream(50)
$data2 = StringSplit($data, "|")

$My_Stream_Size = $data2[0]
$My_Stream = $data2[1]

;.
;..
;... 

    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 / 2, @DesktopHeight / 2) ;resize image

    $sStream_Data = _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)
    
    
      Local $data_size = GetStreamSize($sStream_Data)


    Return $data_size & "|" & $sStream_Data 
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 GetStreamSize($data) ; ??

EndFunc

 

Edited by DrAhmed
Link to comment
Share on other sites

I think you have what you need inside your own code:

Local $iMemSize = _MemGlobalSize($hMemory)

So you could use $GetStreamSize = _MemGlobalSize($bData)

I'm not sure but I think it probably work.

Another way is to analyze RGB data of the image, I don't know if _GDIPlus can do that.

Interesting information here:
http://www.scantips.com/basics1d.html

Regards
Alien.

Link to comment
Share on other sites

4 hours ago, DrAhmed said:

Local $data_size = GetStreamSize($sStream_Data)

This should do it:

Local $data_size = GetStreamSize($sStream_Data)
MsgBox(0, "", BinaryLen($data_size) & " bytes")

 

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...