Image Decoders
TinyCLR can decode JPG, GIF, and BMP images directly into Bitmap objects that the graphics engine can draw to the screen. Source bytes can come from a project resource, an SD card, the network, or anywhere else you can produce a byte[].
NuGet package: GHIElectronics.TinyCLR.Drawing.
note
- BMP — 256-color and 24-bit color depths supported.
- GIF — static images only. Animated GIFs aren't supported.
- JPG — standard baseline JPEG.
Loading from a resource
If the image ships with the application, embed it as a resource and load directly:
var image = Resources.GetBitmap(Resources.BitmapResources.jpegImageFile);
Loading from a byte array
When the image arrives at runtime (SD card, USB drive, downloaded over the network), construct a Bitmap from the bytes and specify the format:
var jpegBitmap = new Bitmap(dataArray, BitmapImageType.Jpeg);
var gifBitmap = new Bitmap(dataArray, BitmapImageType.Gif);
var bmpBitmap = new Bitmap(dataArray, BitmapImageType.Bmp);
Drawing the image
Once you have a Bitmap, draw it to a Graphics surface — see Graphics for the full drawing API:
var screen = Graphics.FromImage(new Bitmap(displayController.ActiveConfiguration.Width,
displayController.ActiveConfiguration.Height));
screen.DrawImage(image, x: 0, y: 0);
screen.Flush();
Saving a bitmap
Save a Bitmap to a stream — useful for writing to an SD card or sending over the network:
using System.Drawing.Imaging;
var bitmap = new Bitmap(data, width, height);
bitmap.Save(fileStream, ImageFormat.Bmp);
Video
For motion content, see Motion JPEG.
API reference
| Namespace | Description |
|---|---|
| GHIElectronics.TinyCLR.Drawing | Bitmap class with built-in JPG, GIF, and BMP decoding |