private void showOnScreen() { Transaction fade = new FadeTransaction(lcd); fade.TransEvent += new TransactionEventHandler(OnTransActionComplete); lcd.UpdateScreen(imgToShow, fade); }
private void drawGeneration() { //Create our bitmap. I'm using System.Drawing as it has way better performance than WPF Canvas or DrawingVisual var bitmap = new System.Drawing.Bitmap(320, 240); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //We need to draw the whole bitmap white, as we're drawing black rectangles on it. //If we don't, we'll just get a completely black image. g.Clear(System.Drawing.Color.White); //Loop through our 2-dimentional array of cells for (int x = 0; x < sim.GridSize.X; x++) { for (int y = 0; y < sim.GridSize.Y; y++) { drawCell(bitmap, g, x, y); } } //We're done. Dispose the Grapghics instance to free up the memory g.Dispose(); //Convert the Drawing's bitmap to Imaging's BitmapImage BitmapImage bmpImg = Utils.ConvertBmpToBmpImg(bitmap); //Freezing the BitmapImage allows for it to be "moved" or accesssed cross threads! bmpImg.Freeze(); //Invoking our UI Thread so we can update the UI Dispatcher.BeginInvoke((Action)(() => { imgOutput.Source = bmpImg; lbGeneration.Content = String.Format("Generation {0}", sim.Generation); //We could take an image of the whole window and send that to the screen also //lcd.UpdateScreen(Utils.GetImage(this)); //Send the image to the screen lcd.UpdateScreen(bmpImg); })); //Dispose the bitmap to remove it from memory. bitmap.Dispose(); }