public byte[] DisplayBuffer; // A working pixel buffer for your code public HX8357Display(string defaultText, int ulValue, int dcpin, int resetpin) { LCD_VERTICAL_MAX = VERTICAL_MAX_DEFAULT; // Y LCD_HORIZONTAL_MAX = HORIZONTAL_MAX_DEFAULT; // X //InitSPI(SpiDevice SPI, int SPIpin, int speed, SpiMode mode, string SPI_CONTROLLER_NAME) DCPin = WS_HX8357.InitGPIO(dcpin, GpioPinDriveMode.Output, GpioPinValue.High); ResetPin = WS_HX8357.InitGPIO(resetpin, GpioPinDriveMode.Output, GpioPinValue.High); cursorX = 0; cursorY = 0; DisplayBuffer = new byte[LCD_VERTICAL_MAX * LCD_HORIZONTAL_MAX * 2]; // A working pixel buffer for your code, RGB565 currentImage = ""; }
public static async Task LoadBitmap(HX8357Display display, string name) { try { StorageFile srcfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(name)); using (IRandomAccessStream fileStream = await srcfile.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream); BitmapTransform transform = new BitmapTransform() { ScaledWidth = Convert.ToUInt32(display.LCD_HORIZONTAL_MAX), ScaledHeight = Convert.ToUInt32(display.LCD_VERTICAL_MAX) }; PixelDataProvider pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage ); byte[] sourcePixels = pixelData.DetachPixelData(); if (sourcePixels.Length != display.LCD_HORIZONTAL_MAX * display.LCD_VERTICAL_MAX * 4) { return; } int pi = 0; for (UInt32 x = 0; x < sourcePixels.Length - 1; x += 4) { // we ignore the alpha value [3] ushort temp = WS_HX8357.RGB24ToRGB565(sourcePixels[x + 2], sourcePixels[x + 1], sourcePixels[x]); display.DisplayBuffer[pi * 2] = (byte)((temp >> 8) & 0xFF); display.DisplayBuffer[pi * 2 + 1] = (byte)(temp & 0xFF); pi++; } } } catch (Exception ex) { throw new Exception(ex.Message); } display.currentImage = name; }