Exemplo n.º 1
0
        private WriteableBitmap GetSurface(PixelBuffer pixelBuffer)
        {
            if (!Monitor.IsEntered(_syncRoot))
            {
                throw new InvalidOperationException();
            }

            WriteableBitmap surface = pixelBuffer.Surface;

            if (surface == null ||
                surface.PixelWidth != pixelBuffer.Width ||
                surface.PixelHeight != pixelBuffer.Height)
            {
                DpiScale dpi = OffscreenGraphics.DpiScale;
                surface             = new WriteableBitmap(pixelBuffer.Width, pixelBuffer.Height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Bgra32, null);
                pixelBuffer.Surface = surface;
            }

            surface.Lock();
            try
            {
                Marshal.Copy(pixelBuffer.DIB, 0, surface.BackBuffer, pixelBuffer.Size);
                surface.AddDirtyRect(pixelBuffer.GetDirtyRectangle());
                pixelBuffer.ClearDirtyRectangle();
            }
            finally
            {
                surface.Unlock();
            }
            return(surface);
        }
Exemplo n.º 2
0
        private WriteableBitmap GetSurface(PixelBuffer pixelBuffer)
        {
            if (!Monitor.IsEntered(_syncRoot))
            {
                throw new InvalidOperationException();
            }

            WriteableBitmap surface = pixelBuffer.Surface;

            if (surface is null || surface.PixelSize != new PixelSize(pixelBuffer.Width, pixelBuffer.Height))
            {
                surface?.Dispose();
                surface             = new WriteableBitmap(new PixelSize(pixelBuffer.Width, pixelBuffer.Height), OffscreenGraphics.DpiScale.Dpi, PixelFormat.Bgra8888, AlphaFormat.Premul);
                pixelBuffer.Surface = surface;
            }

            using (ILockedFramebuffer frameBuffer = surface.Lock())
            {
                Marshal.Copy(pixelBuffer.DIB, 0, frameBuffer.Address, pixelBuffer.Size);
                pixelBuffer.ClearDirtyRectangle();
            }
            return(surface);
        }