OK, I’ve been beating my brains out over this for several days, and I realized that perhaps if I offer up more info on the scenario I’m trying to enable, perhaps some of the sharp folks on the forum can point me to a smarter way to approach the problem.
Basically, what I’m trying to build is an application that will:
-
Capture images from the camera module and display them on the screen, preferably streaming the images until an on-screen button (or could be a button module, not picky) is pressed.
-
Overlay a pre-defined image as a sort of frame for the picture captured by the camera.
-
When the button (on-screen or module) is pressed, capture the screen image, and convert it to a format that can be sent via email.
-
Send an email to a specified email address with the captured image.
I have 75-80% of this working. I am able to stream the images from the camera to the screen. I am able to overlay a predefined image. I am able to capture that image as a bitmap, and I’m able to send a text email (without the image, so far).
Where I’m falling down is getting the image data in a format that’s conducive to sending via email. The road I’ve been going down is to use the ConvertBase64.ToBase64String method, but that was throwing an OutOfMemoryException (per this thread: [url]http://www.tinyclr.com/forum/21/4688/[/url]), so I’m beginning to wonder whether perhaps I’m approaching this the wrong way.
I was able to get ToBase64String to run without exception by chunking up the Byte array using the following code:
string WindowToBase64()
{
byte[] buffer = new byte[8192];
int offsetval = 0;
byte[] imageBytes = window.Graphics.GetBitmap().GetBitmap();
int winlen = imageBytes.Length;
String tempStr = "";
while (offsetval < imageBytes.Length)
{
int length =
System.Math.Min(buffer.Length, imageBytes.Length - offsetval);
Array.Copy(imageBytes, offsetval, buffer, 0, length);
offsetval += length;
tempStr += ConvertBase64.ToBase64String(buffer);
}
return tempStr;
}
The problem with that is that it’s extremely slow, and the resulting string doesn’t appear to be a valid base64 string (or so the desktop framework tells me when I try to convert it back into an image in another program).
Is what I’m trying to do unrealistic for the Spider kit?
Is there another way of doing this that would make more sense?
Thanks in advance for any tips or suggestions.