Jump to content

Recommended Posts

Posted (edited)

Good day you all.
I am new to autoit and are searching fore day's to find How you get a Taken image area screenshot into a memory string.
Like this: 

$FileName = "0xFFD8FFE000104A46494600010101006000600000FFE1001645786966000049492A0008000000000000000000FFDB004300080606070605080707070909080A"

I found it in a tutorial on how to get it From a memory string back into a image :S
 

In short, my idea is to take a screenshot of a area with a selection box and than Not save it as a image file, but as a string like that above in a ini file with all the info of the taken screenshot.
Like size, taken date, and the reason of taking it.
The art thing is that i can only find how to use it to make the image, But not store it in a string like that..

I hope some one can help me with this.

Best Regards

Edited by ingosa
Posted
58 minutes ago, ingosa said:

I hope some one can help me with this.

As usual @UEZ has the answer :lol::

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


#include <Screencapture.au3>
#include <Memory.au3>


_GDIPlus_Startup()
Global $hHBitmap = _ScreenCapture_Capture("", 0, 0, 100, 100)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
Global $bImage = _GDIPlus_StreamImage2BinaryString($hBitmap)
ConsoleWrite("Error: " & @error & @LF)
MsgBox(0, "Binary", $bImage)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_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-u…op/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

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

I think this is what you are looking for :

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

_GDIPlus_Startup()
Local $hBitMap = _ScreenCapture_Capture ("", 50, 50, 100, 100, False)
Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitMap)
_WinAPI_DeleteObject($hBitMap)
Local $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, 51, 51, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
Local $Scan = DllStructGetData($BitmapData, "Scan0")
Local $bData = DllStructCreate("byte string [" & 51 * 51 * 4 & "]",$Scan)
ConsoleWrite ($bData.string & @CRLF)
_GDIPlus_BitmapUnlockBits($hImage, $BitmapData)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

 

Posted
20 minutes ago, Nine said:

I think this is what you are looking for :

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

_GDIPlus_Startup()
Local $hBitMap = _ScreenCapture_Capture ("", 50, 50, 100, 100, False)
Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitMap)
_WinAPI_DeleteObject($hBitMap)
Local $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, 51, 51, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
Local $Scan = DllStructGetData($BitmapData, "Scan0")
Local $bData = DllStructCreate("byte string [" & 51 * 51 * 4 & "]",$Scan)
ConsoleWrite ($bData.string & @CRLF)
_GDIPlus_BitmapUnlockBits($hImage, $BitmapData)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

 

Thanks a lot, that was it yes :)
How can i mark as solved?

Posted
1 minute ago, ingosa said:

How can i mark as solved?

You can change the title and add [SOLVED] at the beginning.  Can I ask you to provide the code you have to recreate the image ?  It may help someone who is looking for it in the future. Thanks.

  • Moderators
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

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