Search code examples
windows-mobilewindows-mobile-6.5opennetcf

Screen capture with OpenNetCF - Missing page title/header


I am testing several implementations of screen capture functionality on Windows Mobile.

Using SO, I find the following method by @ctacke using OpenNetCF.Drawing library (http://blog.opennetcf.com/2009/03/11/screen-capture-in-the-compact-framework/):

// create a bitmap and graphics objects for the capture
Drawing.Bitmap destinationBmp = new Drawing.Bitmap(Forms.Screen.PrimaryScreen.Bounds.Width, Forms.Screen.PrimaryScreen.Bounds.Height);
Drawing.Graphics g = Drawing.Graphics.FromImage(destinationBmp);
GraphicsEx gx = GraphicsEx.FromGraphics(g);

// capture the current screen
gx.CopyFromScreen(0, 0, 0, 0, Forms.Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

// save the file
destinationBmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);

// clean house
gx.Dispose();
g.Dispose();
destinationBmp.Dispose();

I tried to test this method on a simple application on the Windows Mobile 6.5 VGA Emulator and get an unattended result:

The image saved has the right size (480x640), but the content is not the full copy of my screen: the header part is missing and the bottom is "black-padded" (the missing pixel lines are black).

Trying on Windows Mobile 6 emulator, got the same problem. How to get all the screen?


Solution

  • I managed to find the solution by modifying the X and Y fields from the CopyFromScreen call, using the properties of PrimaryScreen.WorkingArea:

    gx.CopyFromScreen(-Forms.Screen.PrimaryScreen.WorkingArea.X, -Forms.Screen.PrimaryScreen.WorkingArea.Y, 0, 0, Forms.Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
    

    Editing this line this way, I got all the screen.