If anyone has a working project, that displays a jpg on Fez Bit, please give me the source, because the tutorial doesn’t work for me as always.
The code below displays a bitmap image from the projects resources.
using System.Drawing;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Drivers.Sitronix.ST7735;
using GHIElectronics.TinyCLR.Pins;
namespace FEZBitDisplay {
class Program {
private static ST7735Controller st7735;
private const int SCREEN_WIDTH = 160;
private const int SCREEN_HEIGHT = 128;
private static void Main() {
var spi = SpiController.FromName(SC20100.SpiBus.Spi4);
var gpio = GpioController.GetDefault();
st7735 = new ST7735Controller(
spi.GetDevice(ST7735Controller.GetConnectionSettings
(SpiChipSelectType.Gpio, gpio.OpenPin(SC20100.GpioPin.PD10))), //CS pin.
gpio.OpenPin(SC20100.GpioPin.PC4), //RS pin.
gpio.OpenPin(SC20100.GpioPin.PE15) //RESET pin.
);
var backlight = gpio.OpenPin(SC20100.GpioPin.PA15);
backlight.SetDriveMode(GpioPinDriveMode.Output);
backlight.Write(GpioPinValue.High);
st7735.SetDataAccessControl(true, true, false, false); //Rotate the screen.
st7735.SetDrawWindow(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
st7735.Enable();
// Create flush event
Graphics.OnFlushEvent += Graphics_OnFlushEvent;
// Create bitmap buffer
var screen = Graphics.FromImage(new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT));
var image = Resources.GetBitmap(Resources.BitmapResources.Pulse);
screen.Clear();
screen.DrawImage(image, 0, 0);
screen.Flush();
Thread.Sleep(Timeout.Infinite);
}
private static void Graphics_OnFlushEvent(Graphics sender, byte[] data, int x, int y, int width, int height, int originalWidth) {
st7735.DrawBuffer(data);
}
}
}
2 Likes
It’s worth noting that the image dimensions may need to be even numbers. See: JPG format is not working but BMP is OK and other useful topics available via forum search.
1 Like