public FormatConvertedBitmap GetFrame() { lock (Gl) { // Render. Gl.Blit(IntPtr.Zero); IntPtr hBitmap = IntPtr.Zero; FormatConvertedBitmap newFormatedBitmapSource = null; switch (RenderContextType) { case RenderContextType.DIBSection: { var provider = Gl.RenderContextProvider as DIBSectionRenderContextProvider; //hBitmap = provider.DIBSection.HBitmap; //break; // TODO: We have to remove the alpha channel - for some reason it comes out as 0.0 // meaning the drawing comes out transparent. newFormatedBitmapSource = new FormatConvertedBitmap(); newFormatedBitmapSource.BeginInit(); newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.DIBSection.HBitmap); newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24; newFormatedBitmapSource.EndInit(); break; } case RenderContextType.NativeWindow: break; case RenderContextType.HiddenWindow: break; case RenderContextType.FBO: { FBORenderContextProvider provider = Gl.RenderContextProvider as FBORenderContextProvider; //hBitmap = provider.InternalDIBSection.HBitmap; //break; // TODO: We have to remove the alpha channel - for some reason it comes out as 0.0 // meaning the drawing comes out transparent. newFormatedBitmapSource = new FormatConvertedBitmap(); newFormatedBitmapSource.BeginInit(); newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.InternalDIBSection.HBitmap); newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24; newFormatedBitmapSource.EndInit(); break; } } //Bitmap res = hBitmap != null ? Bitmap.FromHbitmap(hBitmap) : null; //return res; return(newFormatedBitmapSource); } }
public ImageSource GetFrame() { if (!BlitImage) { return(ImgSource); } lock (Gl) { Gl.Blit(IntPtr.Zero); IntPtr hBitmap = IntPtr.Zero; switch (RenderContextType) { case RenderContextType.DIBSection: { DIBSectionRenderContextProvider provider = Gl.RenderContextProvider as DIBSectionRenderContextProvider; // TODO: We have to remove the alpha channel - for some reason it comes out as 0.0 // meaning the drawing comes out transparent. FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap(); newFormatedBitmapSource.BeginInit(); newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.DIBSection.HBitmap); newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24; newFormatedBitmapSource.EndInit(); // Copy the pixels over. return(newFormatedBitmapSource); } case RenderContextType.NativeWindow: break; case RenderContextType.HiddenWindow: break; case RenderContextType.FBO: { FBORenderContextProvider provider = Gl.RenderContextProvider as FBORenderContextProvider; // TODO: We have to remove the alpha channel - for some reason it comes out as 0.0 // meaning the drawing comes out transparent. FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap(); newFormatedBitmapSource.BeginInit(); newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.InternalDIBSection.HBitmap); newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24; newFormatedBitmapSource.EndInit(); // Copy the pixels over. return(newFormatedBitmapSource); } case RenderContextType.PBO: { PBORenderContextProvider provider = Gl.RenderContextProvider as PBORenderContextProvider; var width = provider.Width; var height = provider.Height; var pixelsPtr = provider.PixelPtr; if (pixelsPtr == IntPtr.Zero) { return(null); } var size = provider.Size; var stride = provider.Stride; var rect = new Int32Rect(0, 0, width, height); WriteableBitmap.WritePixels(rect, pixelsPtr, size, stride, 0, 0); return(WriteableBitmap); } default: break; } } return(null); }