private Bitmap SurfaceToBitmap(Surface surface) { if (surface is JpegSurface) { var bitmap = new Bitmap(surface.CreateStream()); SwapRedAndBlueChannels(bitmap); return bitmap; } else { var bitmap = new Bitmap(surface.Width, surface.Height, PixelFormat.Format32bppArgb); try { var bitmapData = bitmap.LockBits(new Rectangle(0, 0, surface.Width, surface.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); surface.CopyToArgb(new SurfaceData(bitmapData.Width, bitmapData.Height, bitmapData.Scan0, bitmapData.Stride)); bitmap.UnlockBits(bitmapData); return bitmap; } catch { bitmap.Dispose(); throw; } } }
public sealed override Stream CreateStream() { return(@this.CreateStream()); }