LCD Display to Bitmap Structure?

Hi All,

Is there a way to dump whats currently showing on the lcd screen into a variable of bitmap (Microsoft.SPOT.Bitmap) type?

[edit] Talking about the Gadgeteer Spider Kit (T35 LCD) [/edit]

Thanks,
Tom

“simple graphics” is actually a bitmap object do you already have it.

I get that, but is it possible to dump it from there into a different bitmap ? I would like to do something like:



/*
Error	1	Cannot convert type 'Gadgeteer.Modules.Module.DisplayModule.SimpleGraphicsInterface' to 'Microsoft.SPOT.Bitmap'	C:\source\gadgeteer\DebugLCDTest\DebugLCDTest\DebugLCD.cs	43	26	DebugLCDTest
*/

Bitmap curScreen = (Bitmap)lcd.SimpleGraphics;


Then clear the lcd.SimpleGraphics and show some stuff, after a certain point I would like restore the screen to what I had before by displaying curScreen back on the lcd?

The LCD is not the bitmap, simple graphics is, IIRC

Well, one of the two following methods should work:


            //method one, the "proper" way
            using (var bmp = new Bitmap((int)display.Width, (int)display.Height))
            {
                using (var dc = new DrawingContext(bmp))
                {
                    display.WPFWindow.OnRender(dc);
                }

                sdCard.GetStorageDevice().WriteFile("test.bmp", bmp.GetBitmap());
            }

            //method two, the "hacky" way
            var b = display.SimpleGraphics.GetType().GetField("_display", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(display.SimpleGraphics);
            sdCard.GetStorageDevice().WriteFile("test.bmp", ((Bitmap)b).GetBitmap());

However, I must be doing something wrong (GetBitmap()??), because it always writes out nulls to the file.

GetBitmap just gives you any array of pixel data not bitmap formatted and you can’t use it to set pixels. If it werent for being able to manually transform that data into a bmp file it would be totally useless.

OK, good to know. So it’s a matter of serializing the bitmap to the file. Makes sense now that I think about it. Thanks!

GHI library provide a method to convert that byte array to BMP file if you need.

OK, Gus, that helps. I’ve got a Bitmap saving to disk now. But for some reason it’s just all black.

Do you know of a working example where Control.OnRender(dc) to a Bitmap works? My experience with .NET tells me this is the way it should work.

Although, even using reflection and reading the display._display I only see a black bitmap.

I’ll play with it some more, I guess.

There ate some rules about bitmap size but 320x240 works fine.

Did you draw on bitmap before saving it? :slight_smile:

OK, here is the modified code:


            using (var bmp = new Bitmap((int)display.Width, (int)display.Height))
            {
                using (var dc = new DrawingContext(bmp))
                {
                    display.WPFWindow.OnRender(dc);
                }

                var bmpfile = new byte[bmp.Width * bmp.Height * 3 + 54]; //not sure about this overhead, taken from docs
                Util.BitmapToBMPFile(bmp.GetBitmap(), bmp.Width, bmp.Height, bmpfile);
                sdCard.GetStorageDevice().WriteFile("test.bmp", bmpfile); //this results in a white bitmap
            }

            Bitmap bmp1 = (Bitmap)display.SimpleGraphics.GetType().GetField("_display", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(display.SimpleGraphics);
            var bmpfile1 = new byte[bmp1.Width * bmp1.Height * 3 + 54];
            Util.BitmapToBMPFile(bmp1.GetBitmap(), bmp1.Width, bmp1.Height, bmpfile1);

            sdCard.GetStorageDevice().WriteFile("test1.bmp", bmpfile1); //this results in a black bitmap

On screen I’m seeing some text and images. Using either method I get either an all white or all black bitmap.

They are valid bitmaps now, but still blank.

Stepping through the code, I think GetBitmap is still the issue. It appears to be returning an array of 0’s/null bytes.

I was just going to say try a bitmap object, no gadgeteer.

We/you can always request this from the core team. Gadgeteer.codeplex.com

did you ever figure this out? I’m seeing the same thing. very frustrating.

I haven’t tried playing with it recently, particularly after the last few rounds of updates. Are you are the latest versions of the SDK’s and firmware?

Does this help you guys out? It was recently posted in the Codeshare section of the site.

It’s about taking a screen capture and saving to SD.

http://www.tinyclr.com/codeshare/entry/460