Capture Screen and Email

Following up on this, it looks like my problem was related to trying to get a bitmap from the current window contents, rather than grabbing the camera contents.

As noted earlier, originally I pushed the image from the camera onto the screen, then overlaid that with a frame image, and used the following code to attempt to get a byte array representing the screen image:

Byte[] outputBytes = window.Graphics.GetBitmap().GetBitmap();

This would always give me an image size of 307200 bytes, regardless of the image captured, which should have been a clue that something was not quite right. After this, attempts to base64 encode the byte array tended to result in either majorly slow perf, or out of memory exceptions.

Instead, I now capture the image from the camera (in the PictureCaptured event handler), and overlay the frame image, and convert the resulting image to a PC-compatible bitmap file with the following code:

Bitmap bmp = picture.MakeBitmap();
bmp.DrawImage(0, 0, Resources.GetBitmap(Resources.BitmapResources.MyImage), 0, 0, 320, 240);

Byte[] outputBytes = new Byte[bmp.Width * bmp.Height * 3 + 54];

Util.BitmapToBMPFile(bmp.GetBitmap(), 320, 240, outputBytes);

Now, if I base64 encode the outputBytes byte array, it works fairly quickly, and I’m able to dump the string into my email and send.

The last thing I’m chasing down is that the base64 string that is produced by:

ConvertBase64.ToBase64String(outputBytes);

appears to contain some characters that are not valid for base64. Grr!

PS - I’ve posted the updated SMTP code that I put together for this project based on the FEZ email-based door monitor code from the wiki. My code is on the code site here:

http://code.tinyclr.com/project/389/smtp-email-class-for-gadgeteer-based-projects/

Thanks for sharing

this looks almost like what you are doing… but instead of E-mail it streams over TCP…

http://www.pialek.eu/blog/programming/dot-net-micro-framework/10-remote-control-of-a-device-streaming-display-frames-over-tcpip.html

Enjoy!!