private void TranslateBitmap() { byte[] lcdTranslate = new byte[lcd_width * lcd_height]; //draw the open pandora icon Image icon = Base64ToImage(base64pandora16ico); lcd_graphics.DrawImage(icon, 0, 0, icon.Width, icon.Height); // Create temporary color and byte Byte pixelValue; //translate the bitmap to a byte array for (int hIndex = 0; hIndex < lcd_height; ++hIndex) { for (int wIndex = 0; wIndex < lcd_width; ++wIndex) { // Get the green value of the current pixel pixelValue = bmp.GetPixel(wIndex, hIndex).G; // Place it in our translator lcdTranslate[wIndex + (hIndex * lcd_width)] = pixelValue; } } // Send the lcd the translated information lcd.DisplayBitmap(ref lcdTranslate[0], LCDInterface.lglcd_PRIORITY_ALERT); }
/// <summary> /// Fetches the content of the <see cref="Graphics"/> object to the G15 screen. /// </summary> /// <param name="priority"></param> private unsafe void UpdateLcdDisplay(uint priority) { // Locking should not be necesseray but i'll keep it here lock (m_bmpLCD) { int width = m_bmpLCD.Width; int height = m_bmpLCD.Height; byte[] buffer = new byte[width * height]; Rectangle rect = new Rectangle(0, 0, width, height); BitmapData bmData = m_bmpLCD.LockBits(rect, ImageLockMode.ReadOnly, m_bmpLCD.PixelFormat); try { BitmapData bmDataX = m_bmpLCDX.LockBits(rect, ImageLockMode.ReadOnly, m_bmpLCDX.PixelFormat); try { // Extract bits per pixel and length infos int stride = bmData.Stride; int bpp = stride / width; int length = stride * height; // Copy the content of the bitmap to our buffers // Unsafe code removes the boundaries checks - a lot faster. fixed(byte *buffer0 = buffer) { byte *output = buffer0; byte *inputX = (byte *)bmDataX.Scan0.ToPointer(); byte *input = (byte *)bmData.Scan0.ToPointer();; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { *output = (byte)((*input) ^ (*inputX)); inputX += bpp; input += bpp; output++; } } } } finally { m_bmpLCDX.UnlockBits(bmDataX); } } finally { m_bmpLCD.UnlockBits(bmData); } // Fetches the buffer to the LCD screen LCDInterface.DisplayBitmap(ref buffer, priority); } }