Jump to content

ScreenShot ready to send via TCPSend


Recommended Posts

I am making a script to take screenshot on ComputerA then send it to ComputerB but i don't want the screenshot to be write on the HardDisk each time.

An example of my current script:

#include <A3LScreenCap.au3>

Global $ControlledComputerIP = "192.168.0.11" 
Global $ControlledComputerPort = 65432
Global $Socket
Global $Connected = "NO" 

While 1
    If $Connected = "YES"  Then 
        ;Take Screenshot to ScreenShot.jpg
        _ScreenCap_SetJPGQuality (50)
        _ScreenCap_Capture ("ScreenShot.jpg")
        ;Set $DATA with the content of ScreenShot.jpg
        $File = FileOpen("ScreenShot.jpg", 0 + 16);     0=read + 16=binary
        $DATA = "(START)" & FileRead($File) & "(END)" 
        FileClose($File)
        ;Send the ScreenShot to the server
        SendFunc($DATA) 
    Else
        ServerNegociation()
    EndIf
    Sleep(1000)
WEnd

Func ServerNegociation()
;~      ; Start The TCP Services
;~      ;==============================================
;~      TCPStartup()
;~      ; Connect to a Listening "SOCKET"
;~      ;==============================================
;~      $Socket = TCPConnect($ControlledComputerIP, $ControlledComputerPort)
;~      If $Socket = -1 Then
;~           TCPShutdown()
;~           $Connected = "NO"
;~      Else
    $Connected = "YES" 
;~      EndIf
EndFunc   ;==>ServerNegociation

Func SendFunc($DATA)
;~      ;Send DATA to the server
;~      TCPSend($Socket, $DATA)
;~      If @error Then
;~           TCPShutdown()
;~           $Connected = "NO"
;~           $Socket = -1
;~      EndIf
EndFunc   ;==>SendFuncoÝ÷ Ù8^IÊÞzt¡¢Ø¬Â¸­zíáö§­æ~º&¶Â¢jnµêÀmçè­è­q©ÛzǧvÚ¢jnµêÁßr0j{[y¦åzÚ¢Ê&zØb    bëaȧ¶)^.)jëh×6#include <A3LScreenCap.au3>

Global $ControlledComputerIP = "192.168.0.11"
Global $ControlledComputerPort = 65432
Global $Socket
Global $Connected = "NO"
Global $hBitmap

While 1
    If $Connected = "YES"  Then ;
        ;Take Screenshot
        _ScreenCap_SetJPGQuality (50)
        $hBitmap = _ScreenCap_Capture ()
        ;Set $DATA with the content of $hBitmap
        $DATA = "(START)" & $hBitmap & "(END)"
        ;Send the ScreenShot to the server
        SendFunc($DATA) ;
    Else
        ServerNegociation()
    EndIf
    Sleep(1000)
WEnd

Func ServerNegociation()
;~      ; Start The TCP Services
;~      ;==============================================
;~      TCPStartup()
;~      ; Connect to a Listening "SOCKET"
;~      ;==============================================
;~      $Socket = TCPConnect($ControlledComputerIP, $ControlledComputerPort)
;~      If $Socket = -1 Then
;~           TCPShutdown()
;~           $Connected = "NO"
;~      Else
    $Connected = "YES"
;~      EndIf
EndFunc   ;==>ServerNegociation

Func SendFunc($DATA)
;~      ;Send DATA to the server
;~      TCPSend($Socket, $DATA)
;~      If @error Then
;~           TCPShutdown()
;~           $Connected = "NO"
;~           $Socket = -1
;~      EndIf
EndFunc   ;==>SendFunc

What can i do with $hBitmap to get the binary string of the screenshot?

Currently $hBitmap = 0x240508E0

I really need help with the manipulation HBITMAP handle to get the result I want.

Edited by crash748
Link to comment
Share on other sites

hi, i dont understand u very well, but u can read or write a file in a binary form using $file = FileOpen($scre..., 16)

make a file .jpg on the variable $hBitmap and later open with FileOpen....

or just put $hbitmap=binary(_ScreenCap_Capture ())

for recive u have to put the next lines...

remember u can send only a max of 2048bytes....if u want more help go to my post file transfer Tcp/ip http://www.autoitscript.com/forum/index.ph...mp;#entry392656

Func _SockRecv($iSocket)
    Local $sData = Binary("")
    While $sData = "" 
        $sData = TCPRecv($iSocket, 3000)
    WEnd 
    $sData=Binary($sData)
    Return $sData
EndFunc;==>_SockRecv
Edited by andres555
Link to comment
Share on other sites

I have try $hbitmap=binary(_ScreenCap_Capture ()) but i don't get the needed result.

$hbitmap = 0x49080582

If i send this to the server, the server don't receive the jpeg but only the BitMap handle.

I want get the same result as $DATA = FileRead($File) but without the need to save and read the jpeg every time.

#include <A3LScreenCap.au3>
$hBitmap = _ScreenCap_Capture ()
_ScreenCap_SaveImage ("ScreenShot.jpg", $hBitmap)
$File = FileOpen("ScreenShot.jpg", 16)
$DATA = FileRead($File)
FileClose($File)
Edited by crash748
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Inet.au3>
Local $IP = InputBox( "IP Address", "Enter your IP address", @IPAddress1 )
Local $snapfile = @ScriptDir & "\crt411.exe"; file to send
Local $file = FileOpen($snapfile, 16)
Local $output = FileRead($file, FileGetSize($snapfile))
FileClose($file)
Local $bitessss=2000 
Local $ipreceptora=_GetIP() ;public ip of client

; slicing file *******************************************************
if BinaryLen($output)>$bitessss Then
    $entero=Int(BinaryLen($output)/$bitessss)
    Dim $data[$entero+1]
    Local $c=1
    Local $i=0
    $Form1_2 = GUICreate("Utilidades1", 261, 298, 377, 242)
$Label22 = GUICtrlCreateLabel("", 56, 184, 136, 17)
GUISetState(@SW_SHOW)
    While $i<=$entero-1 
        $nMsg = GUIGetMsg()
            GUICtrlSetData ( $Label22, $i&"   de "&$entero-1 )
        $data[$i]=BinaryMid( $output,$c , $bitessss )
        $c=$c+$bitessss
    $i=$i+1
    WEnd
    $data[$i]=BinaryMid( $output,$c)
Else
    $entero=0
    Dim $data[1]
    $data[0]=$output
EndIf

later u have to send thats packet to the other server

look my post i do the same that u want to do the only diferent i read anyfile on my script

Edited by andres555
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Inet.au3>
Local $IP = InputBox( "IP Address", "Enter your IP address", @IPAddress1 )
Local $snapfile = @ScriptDir & "\crt411.exe"; file to send
Local $file = FileOpen($snapfile, 16)
Local $output = FileRead($file, FileGetSize($snapfile))
FileClose($file)
Local $bitessss=2000 
Local $ipreceptora=_GetIP();public ip of client

; slicing file *******************************************************
if BinaryLen($output)>$bitessss Then
    $entero=Int(BinaryLen($output)/$bitessss)
    Dim $data[$entero+1]
    Local $c=1
    Local $i=0
    $Form1_2 = GUICreate("Utilidades1", 261, 298, 377, 242)
$Label22 = GUICtrlCreateLabel("", 56, 184, 136, 17)
GUISetState(@SW_SHOW)
    While $i<=$entero-1 
        $nMsg = GUIGetMsg()
            GUICtrlSetData ( $Label22, $i&"   de "&$entero-1 )
        $data[$i]=BinaryMid( $output,$c , $bitessss )
        $c=$c+$bitessss
    $i=$i+1
    WEnd
    $data[$i]=BinaryMid( $output,$c)
Else
    $entero=0
    Dim $data[1]
    $data[0]=$output
EndIf

later u have to send thats packet to the other server

look my post i do the same that u want to do the only diferent i read anyfile on my script

It's certain but for now i think i will look at the PaulIA work to learn how I can do my Screen Capture manipulation.
Link to comment
Share on other sites

  • 2 weeks later...

I have try $hbitmap=binary(_ScreenCap_Capture ()) but i don't get the needed result.

$hbitmap = 0x49080582

If i send this to the server, the server don't receive the jpeg but only the BitMap handle.

I want get the same result as $DATA = FileRead($File) but without the need to save and read the jpeg every time.

$hBitmap = _ScreenCap_Capture ()
_ScreenCap_SaveImage ("ScreenShot.jpg", $hBitmap)
$File = FileOpen("ScreenShot.jpg", 16)
$DATA = FileRead($File)
FileClose($File)
he wants to send images from screen (screenshots) to another computer WITHOUT screencapturing to harddisk. is it possible to send data from a variable (ram) to another computer (without any file access)?

btw: how can i adjust the jpeg compression quality using GDI+ (auto3lib)?

Link to comment
Share on other sites

he wants to send images from screen (screenshots) to another computer WITHOUT screencapturing to harddisk. is it possible to send data from a variable (ram) to another computer (without any file access)?

Did anybody with some experience can say if it was possible or not? If it was possible to write it in a file why it should not be possible to put it in a variable?
Link to comment
Share on other sites

it is possible, dont know if possible with autoit...

some ideas (what i remember):

- pipes for redirecting file output?

- reading memory (ram, at address where the image is saved)

- autoit script-internal conversion to image format (bmp/jpg/png/...)

- "take over" of the data stream (possible in "real" programming languages like c++ or .net but very difficult)

http://msdn.microsoft.com/library/default....usreference.asp

http://msdn2.microsoft.com/en-us/library/ms535410.aspx

@crash748:

doesn't work and doesn't use gdi+ as far as i can see... should be something like this:

; Set up parameters for compression quality

$tData = DllStructCreate("int Data")

DllStructSetData($tData, "Data", $GDIP_EPGQUALITY)

$tParams = _GDIP_ParamInit(1)

_GDIP_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))

_GDIP_ImageSaveToFileEx ($aSlice[$iI], "C:\A3LSlice" & $iI & ".jpg", $sCLSID, $tParams)

Edited by CoDEmanX
Link to comment
Share on other sites

it is possible, dont know if possible with autoit...

some ideas (what i remember):

- pipes for redirecting file output?

- reading memory (ram, at address where the image is saved)

- autoit script-internal conversion to image format (bmp/jpg/png/...)

- "take over" of the data stream (possible in "real" programming languages like c++ or .net but very difficult)

http://msdn.microsoft.com/library/default....usreference.asp

http://msdn2.microsoft.com/en-us/library/ms535410.aspx

@crash748:

doesn't work and doesn't use gdi+ as far as i can see... should be something like this:

Your right i make a mistake there the code to change the quality of the .jpg

#include <A3LScreenCap.au3>
#include <A3LGDIPlus.au3>

Local $sCLSID, $tData, $hImage, $pParams, $tParams
Global $JPGQuality = 75   ;1-100

; Load image
$hBitmap = _ScreenCap_Capture ("")

; Start GDI
_GDIP_StartUp ()
; Convert my screenshot (bitmap handle) to (Bitmap object)
$hImage = _GDIP_BitmapCreateFromHBITMAP ($hBitmap)

; Jpeg Setting
$sCLSID = _GDIP_EncodersGetCLSID ("JPG")
$tParams = _GDIP_ParamInit (1)
$tData = DllStructCreate("int Quality")
DllStructSetData($tData, "Quality", $JPGQuality)
_GDIP_ParamAdd ($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData))
If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)

; Save the image
_GDIP_ImageSaveToFileEx ($hImage, "Image.jpg", $sCLSID, $pParams)

; Clean Up
_GDIP_ImageDispose ($hImage)
_API_DeleteObject ($hBitmap)

; Stop GDI
_GDIP_ShutDown ()

Thanks for your tip! Maybe i will find something!

Link to comment
Share on other sites

check this out!

In Memory Image Compression C++ (VC7.1 / VC7 / VC6)

we have to ask the author for a dll, cause i assume we can't do the same using AutoIt...

//edit: asked him ("Memory Image Compression DLL?")

I am not familiar with AutoIt-Scripting, but if the script can utilize COM, then it should be able to utilize IStream object. I am not really sure that rewriting the application to be a DLL would solve your problem. Possibly, the best solution would be to provide COM capabilities to the scripting language.

Sorry I could not be of more help!

Edited by CoDEmanX
Link to comment
Share on other sites

  • 2 weeks later...

ok, i have still no idea how to manage but i let my mind wander:

// load image
Image image(L"Nice.bmp");

we need an image:

; Initialize GDI+ library
_GDIP_StartUp()

; Capture screen
$hBitmap  = _ScreenCap_Capture("C:\A3LImage.bmp")

; Load image and emboss text
$hImage   = _GDIP_ImageLoadFromFile("C:\A3LImage.bmp")oÝ÷ ÙÊ{ÿ­æ­zËky©°Øt²,Þ!+ky©©!+ky©oÝ÷ ÙÊ{ÿÒj÷­è¦j­¢Ø^²ÚÞjd­jÛ¬I«ÞJÖ­º

// get the size of the stream
ULARGE_INTEGER ulnSize;
LARGE_INTEGER lnOffset;
lnOffset.QuadPart = 0;
if(pIStream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize) != S_OK)
{
    pIStream->Release();
    AfxMessageBox(_T("Failed to get the size of the stream!"));
    return;
}

// now move the pointer to the beginning of the file
if(pIStream->Seek(lnOffset, STREAM_SEEK_SET, NULL) != S_OK)
{
    pIStream->Release();
    AfxMessageBox(_T("Failed to move the file pointer to "
        "the beginning of the stream!"));
    return;
}

// here you can do what ever you want
/*
    1. You can use global memory
        HGLOBAL hg;
        if(GetHGlobalFromStream(pIStream, &hg) = S_OK)
        ... use hg for something

        2. Copy it into some other buffer
        char *pBuff = new char[ulnSize.QuadPart];

        // Read the stream directly into the buffer
        ULONG ulBytesRead;
        if(pIStream->Read(pBuff, ulnSize.QuadPart, &ulBytesRead) != S_OK)
        {
            pIStream->Release();
            return;
        }
*/

// I am going to save it to the file just so we can 
// load the jpg to a gfx program
CFile fFile;
if(fFile.Open(_T("test.jpg"), CFile::modeCreate | CFile::modeWrite))
{
    char *pBuff = new char[ulnSize.QuadPart];

    // Read the stream directly into the buffer
    ULONG ulBytesRead;
    if(pIStream->Read(pBuff, ulnSize.QuadPart, &ulBytesRead) != S_OK)
    {
        pIStream->Release();
        delete pBuff;
        return;
    }

    fFile.Write(pBuff, ulBytesRead);
    fFile.Close();
    delete pBuff;
}
else AfxMessageBox(_T("Failed to save data to the disk!"));

// Free memory used by the stream
pIStream->Release();

no idea at all... :)

AutoIt Lib 3 has some memory functions, eg. _Mem_GlobalAlloc($iBytes[, $iFlags]) or _Mem_CtrlRead(ByRef $tMemMap, $pSrce, $pDest, $iSize).

anybody who can help us?

Link to comment
Share on other sites

  • 5 weeks later...

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