Jump to content
Sign in to follow this  
lee321987

Assign _ScreenCapture_Capture bitmap (binary data) to a variable?

Recommended Posts

lee321987

Hello.

I'm trying to find a way to get the binary data (not the handle) of the bitmap created by _ScreenCapture_Capture into a variable.

Example:

I'd like to make $data equal what this code makes it equal, but without reading from disk:

#include <ScreenCapture.au3>
_ScreenCapture_Capture("C:\output.bmp")
$fh = FileOpen("C:\output.bmp", 16)
$data = FileRead("C:\output.bmp")

Share this post


Link to post
Share on other sites
UEZ

I assume you are looking for something like this here: 

Br,

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
lee321987

Thank you, but I can't see anywhere in there that a variable ends up holding the binary data of an image.

I tried these two:

$hBitmapFromStream

$hGraphics

but they are just handles.

Am I missing something?

Edited by lee321987

Share this post


Link to post
Share on other sites
UEZ

Ok then try this

 

;Coded by UEZ 2013 -> This program requires AutoIt version 3.3.9.21 or higher!

#AutoIt3Wrapper_Autoit3Dir=c:\Program Files (x86)\AutoIt3\Beta

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

_GDIPlus_Startup()
Global $sFile = StringReplace(@AutoItExe, "autoit3.exe", "Examples\GUI\msoobe.jpg")
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile)
Global $hBitmap = _GDIPlus_ImageResize($hImage, 10, 7)
Global $bImage = _GDIPlus_StreamImage2BinaryString($hBitmap)
ConsoleWrite("Error: " & @error & @LF)
MsgBox(0, "Binary", $bImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

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

Requires AutoIt version 3.3.9.21 or higher!

 

 

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
lee321987

It works!

Thank you very very much!!

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
Sign in to follow this  

×