I’m trying to create a remote desktop-esque program, and am currently trying to get an image of what’s on my remote PC, and send it back over to my client PC to update their image (This happens ever 2-3 seconds.)
I currently get the image of the desktop like this:
// Set up a bitmap of the correct size
Bitmap CapturedImage = new Bitmap((int)SystemInformation.VirtualScreen.Width,
(int)SystemInformation.VirtualScreen.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);
// Create a graphics object from it
System.Drawing.Size size = new System.Drawing.Size((int)SystemInformation.VirtualScreen.Width, (int)SystemInformation.VirtualScreen.Height);
using (Graphics gr = Graphics.FromImage(CapturedImage))
{
// copy the entire screen to the bitmap
gr.CopyFromScreen(0, 0, 0, 0,
size, CopyPixelOperation.SourceCopy);
}
EncodeToJPEG(CapturedImage);
And EncodeToJPEG looks like this:
var qualityEncoder = Encoder.Quality;
var quality = (long)0;
var ratio = new EncoderParameter(qualityEncoder, quality );
var codecParams = new EncoderParameters(1);
codecParams.Param[0] = ratio;
var jpegCodecInfo = GetEncoder(ImageFormat.Jpeg);
capturedImage.Save(@"c:\Test.jpg", jpegCodecInfo, codecParams); // Save to JPG
My question comes from the Save method. I was wondering if there was a way to temporarily store this JPG just long enough for me to have it to send back over the network, instead of saving it to a file? Like, can I return an Image object that is a compressed JPG? Or is this just not possible this way?
I’ve also heard that for these purposes, splitting the image into blocks, and checking their deltas and only sending back the changes is the most efficient way to update images like this faster. If anyone has any pointers in that department I’d be very grateful.
Encoder has method of OVERLOAD name of Save
Arugument to pass is the Stream
You will save to MemoryStream for the memory block save
No files !!
Best ,
PRASHANT 🙂