views:

54

answers:

0

I'm coding a live control/remote desktop solution using DFMirage's free mirror driver. There is a C# sample on how to interface and control the mirror driver here (http://www.demoforge.com/sdk/MirrSharp.zip). You would need the mirror driver installed first, of course, here (http://www.demoforge.com/tightvnc/dfmirage-setup-2.0.301.exe). So, the concept is, the client (helper) requests a screen update, and the server (victim) sends one, using raw pixel encoding. The concept of a mirror driver eliminates the need to expensively poll for screen changes, because a mirror driver is notified of all screen drawing operations in realtime. The mirror driver receives the location and size of the update rectangle, and can simply query memory for the new pixel bytes and send them. Should be easy, except that I don't know how to do that part where we "query memory for the new pixel bytes". The sample shows how to query memory to grab the pixels of the entire screen using something with raw bitmap data and scan lines and stride and all that good stuff:

    Bitmap result = new Bitmap(_bitmapWidth, _bitmapHeight, format);
    Rectangle rect = new Rectangle(0, 0, _bitmapWidth, _bitmapHeight);
    BitmapData bmpData = result.LockBits(rect, ImageLockMode.WriteOnly, format);
// Get the address of the first line.
    IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
    int bytes = bmpData.Stride * _bitmapHeight;
    var getChangesBuffer = (GetChangesBuffer) Marshal.PtrToStructure(_getChangesBuffer, typeof (GetChangesBuffer));
    var data = new byte[bytes];
    Marshal.Copy(getChangesBuffer.UserBuffer, data, 0, bytes);
// Copy the RGB values into the bitmap.
    Marshal.Copy(data, 0, ptr, bytes);
    result.UnlockBits(bmpData);
    return result;

This is great and works fine. The resulting Bitmap object now has the pixels of the entire screen. But if I wanted to just extract a rectangle of pixel data instead of getting the pixel data from the whole screen, how would I be able to do that? I guess this is more of a rawbitmap-scan-stride question, but I typed all of this so you might know where this is coming from ;/ So any insight on how to get just a portion of pixel data instead of the entire screen's pixel data?


Found something interesting (code portion only): http://www.codeproject.com/KB/GDI-plus/ImageMultification.aspx