Screenshot of UI (Window-Class)

Is there a way to take a screenshot of the current UI (4.3" 480x272).

My attempt:

 var Screen = Graphics.FromHdc(Display.DisplayController.Hdc);
 byte[] bmp = Screen.GetBitmap(0, 0, 480, 272);
 var bm = new Bitmap(bmp, 480, 272);

 using (var FileHandle = new FileStream(fi.FullName, FileMode.Create))
           bm.Save(FileHandle, System.Drawing.Imaging.ImageFormat.Bmp);

produces only a black bitmap

You need to call this somewhere before start UI, probably in main().

Graphics.OnFlushEvent += Graphics_OnFlushEvent;

Then every time UI flush to screen , it will trigger function Graphics_OnFlushEvent, then you take data, convert to bitmap and save to bmp format.

Example below:

private static void Graphics_OnFlushEvent(Graphics sender, byte[] data, int x, int y, int width, int height, int originalWidth)
            Debug.WriteLine("count flush " + count++);

            var bmpBitmap = new Bitmap(data, width, height);

            var sdController = StorageController.FromName(SC20260.StorageController.SdCard);

            var provider = FileSystem.Mount(sdController.Hdc);

            var stream = new FileStream(@"A:\UICapture.bmp", FileMode.CreateNew);

            bmpBitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);


1 Like

:grinning: Works great :+1:

1 Like

Thank for feedback.

The code above just for paste and run, easy for user.

When implement to project, should not call Mount/Unmount every time UI flush, it will slow down system a lot.