Not sure whether this question is more of a Gadgeteer/Spider question, or a Glide question, but I’m going to try it here first…feel free to point me to the Glide forum if that’s more apropos.
Anyway, here’s the question…I’m working on a project where I want to capture a picture from the Gadgeteer camera module, display it on the LCD (along with some other graphics, potentially), and then take the contents of the window and convert it to a bitmap, and from there to a base64 string.
I’m using Glide to build the UI, and everything’s working fine right up to the point of the base64 conversion, which throws an OutOfMemoryException.
Here’s the code for initializing and loading the window:
// Resize any loaded Window to the LCD's size. Glide.FitToScreen = true; GlideTouch.Initialize(); // Load the Window XML string. window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Screen1)); // Assign the Window to MainWindow; rendering it to the LCD. Glide.MainWindow = window;
After capturing a picture from the camera to the screen, I then call the following code to grab a bitmap of the screen:
Bitmap outputImage = window.Graphics.GetBitmap(); String imageAttach = ConvertBase64.ToBase64String(outputImage.GetBitmap());
The first line executes without issues, and if I step through, outputImage appears to contain a Bitmap object. But when I call ToBase64String on the outputImage’s GetBitmap result, the aforementioned OutOfMemoryException gets thrown.
Am I doing something wrong here? Is there another way to approach converting an image or window to base64?