I need fastest way to transfer bitmap object over the lan in C#.
Abdul Khaliq
I need fastest way to transfer bitmap object over the lan in C#.
Abdul Khaliq
The word "best" is, at best, a subjective term :-)
If you're talking about speed, then it depends on how big the bitmap is. With a LAN running at 100Mbps, you can expect something roughly around 1 second for each 10MB of file. For a small file, just transfer it as-is. At some file size, it will become worth zipping the file up, transmitting it and unzipping it at the other end, simply because CPU grunt is faster than network grunt.
But I think you'd be talking about pretty big files to make that extra coding worthwhile.
Update:
Since you talk about a screen capture frame, let's say we're at 1280x1024, 32bpp. A full screen will then take up 5M which should be transferable on a 100Mbps LAN in under a second (other network traffic permitting). It's not worth it, in my opinion, to try and speed that up any more since the overhead of compression would outweigh the savings in time.
If you will be doing video transfer, that's another matter. Then you wouldn't send a brand new image for every frame - you'd work out the deltas and transfer only that information, relying on the fact that the screen generally only changes a little each frame.
It depends on what you're going to use the images for. A one-shot screen capture, just send the binary information. Anything else, well, you'll need to give us more detail.
For video transfer, we've actually done some work on different compression methods.
The simplest you may want to look at is to divide the screen into a (e.g.) 16x16 matrix and only transmit the changed elements.
So, for example, each frame will consist of a 256-bit bitmask indicating which elements have changed. Then, that bitmask is followed by the elements themselves.
That algorithm means the smallest frame delta is 32 bytes (if the screen hasn't changed). The largest is only 32 bytes larger than a full screen dump.
One of the other methods we used was to simply store the topleft-most and bottomright-most pixel positions that had changed and transfer those two values along with the entire rectangle bounded by them.
No doubt there are other methods you could use, even choosing the method dynamically on a frame-by-frame basis to ensure minimum delta size.
here's a bug in the .NET V2.0 SP1 and .NET 3.5 version of CopyFromScreen(). It leaks a handle, after a while you'll run out available handles and get weirdo error messages like this. You can't use it in its present condition, check this thread for another way to do it by P/Invoking Windows API functions.
also there is a nice solution found on this link.