/// <summary> /// Callback that runs when the application flushes the LCD buffer to /// the screen. Copies the emulator's internal bitmap to the control. /// </summary> /// <param name="sender">The emulator component firing the event. /// </param> /// <param name="args">What is being redrawn.</param> private void OnDevicePaint(object sender, OnDevicePaintEventArgs args) { Bitmap bitmap = args.Bitmap; if (_bitmap == null) { // The first time the callback occurs, simply make a copy of the // LCD bitmap. This is necessary so the .NET Micro Framework // can draw on its frame buffer after this callback returns. _bitmap = (Bitmap)bitmap.Clone(); } else { // Synchronize the _bitmap object to prevent conflict between // the Micro Framework thread (which this callback runs on) and // the UI thread (which runs during paint). lock (_bitmap) { Rectangle rectangle = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); // Lock the source and target bitmaps in memory so they // can't move while we're copying them. BitmapData bdSrc = bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); BitmapData bdDst = _bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); // Copy the bitmap data, 4 bytes (an int) at a time, using // unsafe code. Copying the entire frame buffer can be // substantially slower in safe code unsafe { int *src = (int *)bdSrc.Scan0.ToPointer(); int *dst = (int *)bdDst.Scan0.ToPointer(); int cInts = bdSrc.Stride / 4 * bitmap.Height; Debug.Assert(bdSrc.Stride > 0); Debug.Assert(bitmap.Width == _bitmap.Width); Debug.Assert(bitmap.Height == _bitmap.Height); Debug.Assert(bitmap.PixelFormat == _bitmap.PixelFormat); for (int i = 0; i < cInts; i++) { *dst++ = *src++; } } // Unlock the source and target bitmaps. bitmap.UnlockBits(bdSrc); _bitmap.UnlockBits(bdDst); } } // Force this control to be redrawn. this.Invalidate(); }
/// <summary> /// A callback function that occurs when the MicroFramework application /// flushes the LCD buffer to the screen. /// </summary> /// <param name="sender">The emulator component firing the event. /// </param> /// <param name="args">Specifies what is being redrawn.</param> private void OnDevicePaint(object sender, OnDevicePaintEventArgs args) { Bitmap bitmap = args.Bitmap; if (_bitmap == null) { // The first time the callback occurs, make a copy of the LCD // contents. A copy must be created, because when this callback // returns, the MicroFramework is able to write into the frame // buffer. _bitmap = (Bitmap)bitmap.Clone(); } else { // Lock the _bitmap object. This bitmap is accessed on the // MicroFramework thread, during this callback. This bitmap is // also accessed on the UI thread, during paint. lock (_bitmap) { Rectangle rectangle = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); // Copy bitmap data. BitmapData bdSrc = bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); BitmapData bdDst = _bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); // Copying the entire frame buffer can be substantially // slower in safe code. Copy the bitmap data, 4 bytes at a // time. unsafe { int* src = (int*)bdSrc.Scan0.ToPointer(); int* dst = (int*)bdDst.Scan0.ToPointer(); int cInts = bdSrc.Stride / 4 * bitmap.Height; Debug.Assert(bdSrc.Stride > 0); Debug.Assert(bitmap.Width == _bitmap.Width); Debug.Assert(bitmap.Height == _bitmap.Height); Debug.Assert(bitmap.PixelFormat == _bitmap.PixelFormat); for (int i = 0; i < cInts; i++) { *dst++ = *src++; } } bitmap.UnlockBits(bdSrc); _bitmap.UnlockBits(bdDst); } } this.Invalidate(); }
/// <summary> /// A callback function that occurs when the MicroFramework application /// flushes the LCD buffer to the screen. /// </summary> /// <param name="sender">The emulator component firing the event. /// </param> /// <param name="args">Specifies what is being redrawn.</param> private void OnDevicePaint(object sender, OnDevicePaintEventArgs args) { Bitmap bitmap = args.Bitmap; if (_bitmap == null) { // The first time the callback occurs, make a copy of the LCD // contents. A copy must be created, because when this callback // returns, the MicroFramework is able to write into the frame // buffer. _bitmap = (Bitmap)bitmap.Clone(); } else { // Lock the _bitmap object. This bitmap is accessed on the // MicroFramework thread, during this callback. This bitmap is // also accessed on the UI thread, during paint. lock (_bitmap) { Rectangle rectangle = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); // Copy bitmap data. BitmapData bdSrc = bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); BitmapData bdDst = _bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); // Copying the entire frame buffer can be substantially // slower in safe code. Copy the bitmap data, 4 bytes at a // time. unsafe { int *src = (int *)bdSrc.Scan0.ToPointer(); int *dst = (int *)bdDst.Scan0.ToPointer(); int cInts = bdSrc.Stride / 4 * bitmap.Height; Debug.Assert(bdSrc.Stride > 0); Debug.Assert(bitmap.Width == _bitmap.Width); Debug.Assert(bitmap.Height == _bitmap.Height); Debug.Assert(bitmap.PixelFormat == _bitmap.PixelFormat); for (int i = 0; i < cInts; i++) { *dst++ = *src++; } } bitmap.UnlockBits(bdSrc); _bitmap.UnlockBits(bdDst); } } this.Invalidate(); }
/// <summary> /// Callback that runs when the application flushes the LCD buffer to the screen to copy the emulator's internal bitmap to our control. /// </summary> /// <param name="sender">The emulator component firing the event</param> /// <param name="args">What is being redrawn</param> private void OnDevicePaint(object sender, OnDevicePaintEventArgs args) { Bitmap bitmap = args.Bitmap; if (_bitmap == null) { // The first time the callback occurs, simply make a copy of the LCD bitmap. Necessary // so the .NET Micro Framework can draw on its frame buffer after this callback returns. _bitmap = (Bitmap)bitmap.Clone(); } else { // Synchronize the _bitmap object to prevent conflict between the Micro Framework thread (which this // callback runs on) and the UI thread (which runs during paint). lock (_bitmap) { Rectangle rectangle = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); // Lock the source and target bitmaps in memory so they can't move while we're copying them BitmapData bdSrc = bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); BitmapData bdDst = _bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); // Copy the bitmap data, 4 bytes (an int) at a time, using unsafe code. // Copying the entire frame buffer can be substantially slower in safe code unsafe { int* src = (int*)bdSrc.Scan0.ToPointer(); int* dst = (int*)bdDst.Scan0.ToPointer(); int cInts = bdSrc.Stride / 4 * bitmap.Height; Debug.Assert(bdSrc.Stride > 0); Debug.Assert(bitmap.Width == _bitmap.Width); Debug.Assert(bitmap.Height == _bitmap.Height); Debug.Assert(bitmap.PixelFormat == _bitmap.PixelFormat); for (int i = 0; i < cInts; i++) { *dst++ = *src++; } } // Unlock the source and target bitmaps bitmap.UnlockBits(bdSrc); _bitmap.UnlockBits(bdDst); } } // Force this control to be redrawn this.Invalidate(); }