Esempio n. 1
0
        public IImageBuffer SKBitmapToImageBuffer(SKBitmap bitmap)
        {
            if (bitmap == null)
            {
                return(null);
            }

            if (bitmap.ColorType != SKColorType.Rgba8888 && bitmap.ColorType != SKColorType.Bgra8888 && bitmap.ColorType != SKColorType.Gray8)
            {
                // try to convert image to 32BPP bitmap if source pixel format is unknown
                if (!bitmap.CanCopyTo(SKColorType.Rgba8888))
                {
                    throw new NotSupportedException("SKImage Input pixel format not supported.");
                }

                using (bitmap = bitmap.Copy(SKColorType.Rgba8888))
                {
                    return(ToImageBuffer(bitmap));
                }
            }
            else
            {
                return(ToImageBuffer(bitmap));
            }
        }
Esempio n. 2
0
            public PixelFormatConversionShim(SKImageInfo destinationInfo, IntPtr framebufferAddress)
            {
                _destinationInfo    = destinationInfo;
                _framebufferAddress = framebufferAddress;

                // Create bitmap using default platform settings
                _bitmap = new SKBitmap(destinationInfo.Width, destinationInfo.Height);

                if (!_bitmap.CanCopyTo(destinationInfo.ColorType))
                {
                    _bitmap.Dispose();

                    throw new Exception(
                              $"Unable to create pixel format shim for conversion from {_bitmap.ColorType} to {destinationInfo.ColorType}");
                }

                Surface = SKSurface.Create(_bitmap.Info, _bitmap.GetPixels(), _bitmap.RowBytes);

                if (Surface == null)
                {
                    _bitmap.Dispose();

                    throw new Exception(
                              $"Unable to create pixel format shim surface for conversion from {_bitmap.ColorType} to {destinationInfo.ColorType}");
                }

                SurfaceCopyHandler = Disposable.Create(CopySurface);
            }
            public PixelFormatShim(SKImageInfo nfo, IntPtr fb, int rowBytes)
            {
                _nfo      = nfo;
                _fb       = fb;
                _rowBytes = rowBytes;


                _bitmap = new SKBitmap(nfo.Width, nfo.Height);
                if (!_bitmap.CanCopyTo(nfo.ColorType))
                {
                    _bitmap.Dispose();
                    throw new Exception(
                              $"Unable to create pixel format shim for conversion from {_bitmap.ColorType} to {nfo.ColorType}");
                }
            }