Question

I have the basic viewing fundamentals working but i'm now wanting to implement a more sophisticated system. I have a method that returns a Bitmap containing a subset that is the minimum rectangular area that encompasses all the changed pixels of the screen. So instead of simply using a BinaryFormatter to serialize the full desktop snapshot over a NetworkStream and then back into a Bitmap to view, i now want to pass the updated pixels Bitmap and its rectangular bounds data, so that i can effectively glue the updated pixels in the correct place on top of the first desktop snapshot (which is sent upon starting the session).

What is the best way to go about sending/receiving a Bitmap and a Rectangle together for this type of protocol?

Really appreciate any help.

Was it helpful?

Solution

I found shortly after posting this question that BinaryFormatter's Serialize/Deserialize has a System.Runtime.Remoting.Messaging.Headers[] parameter. I was able to effectively process the data like so:

Client:

Rectangle bounds = Rectangle.Empty;
Bitmap image = Utils.Screen(ref bounds);
BinaryFormatter bFormat = new BinaryFormatter();
Header[] headers = { new Header("bounds", bounds) };
bFormat.Serialize(stream, image, headers);

Server:

BinaryFormatter bFormat = new BinaryFormatter();
Rectangle bounds = new Rectangle();
Bitmap inImage = bFormat.Deserialize
(
    stream, 
    headers => 
    {
        foreach(var header in headers)
        {
            if(header.Name == "bounds")
                bounds = (Rectangle)header.Value;
        }
        return null;
    }
) as Bitmap;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top