Remote Control article: Crawl Remote screen image

Source: Internet
Author: User

Remote Control article: Crawl Remote screen image

{Capture screen image, save as memory stream--bmp stream, compress bmp stream, JPG stream, and use stream}
{The speed of transmitting BMP and JPG streams in the network has not been tested}
{Compression of BMP stream is lossless compression}
{
Global variables
Memorystream:tmemorystream;
Memorystream:=tmemorystream.create;
}

Var
Image:timage;
Jpgstream:tjpegimage;
Ss:tcanvas;

Begin
Ss:=tcanvas. Create;
Ss. HANDLE:=GETDC (0);
Image:=timage. Create (self);
Image.width:=screen.width;
Image. Height:=screen. Height;
Image.picture.bitmap.pixelformat:= Pf16bit;
BitBlt (image.canvas.handle,0,0,image.width,image.height,ss.handle,0,0,srccopy);

{Large raw BMP stream
Image.picture.bitmap.SaveToStream (MemoryStream);
}

{Lossless compression BMP stream uses Zlib.pas
{First define variable Count,deststream,sourcestream}
Image.picture.bitmap.SaveToStream (MemoryStream);
Count:=memorystream.size;
Deststream:=tmemorystream.create;
{compression mode: Clnone,clfastest,cldefault,clmax}
Sourcestream:=tcompressionstream.create (Cldefault, Deststream);
Try
Memorystream.savetostream (Sourcestream);
Sourcestream.free;
Memorystream.clear;
Memorystream.writebuffer (Count, SizeOf (count));
Memorystream.copyfrom (deststream, 0);
Finally
Deststream.free;
End
}

{JPG stream uses JPEG
Jpgstream:= tjpegimage.create;
Jpgstream. Assign (IMAGE.PICTURE.BITMAP);
jpgstream.compressionquality:=50; {Compression quality}
jpgstream.compress;
Jpgstream. Savetostream (MemoryStream); {Save as JPG stream}
Jpgstream.free;
}

ReleaseDC (0,SS. Handle);
Image.free;

{Send memory Stream ...}

-----------------------------------------------------
{Receive memory Stream ...}

{Using BMP Streams
Image. Picture.Bitmap.LoadFromStream (Bmpstream);}

{Restore compressed BMP stream Uses:Zlib.pas
First define the variable Count,buffer,deststream,sourcestream
MemoryStream is a compressed BMP stream
Memorystream.readbuffer (Count, SizeOf (count));
Getmem (Buffer, Count);
Deststream:=tmemorystream.create;
Sourcestream:=tdecompressionstream.create (MemoryStream);
Try
Sourcestream.readbuffer (buffer^, Count);
Deststream.writebuffer (buffer^, Count);
deststream.position:=0;
Image. Picture.Bitmap.LoadFromStream (Deststream);
Finally
Freemem (Buffer);
Deststream.free;
End
}

Use the JPG stream image. Picture.assign (Jpgstream);

Remote Control article: Crawl Remote screen image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.