示例#1
0
        public ImmutableBitmap(Stream stream, int decodeSize, bool horizontal, BitmapInterpolationMode interpolationMode)
        {
            using (var skStream = new SKManagedStream(stream))
                using (var codec = SKCodec.Create(skStream))
                {
                    var info = codec.Info;

                    // get the scale that is nearest to what we want (eg: jpg returned 512)
                    var supportedScale = codec.GetScaledDimensions(horizontal ? ((float)decodeSize / info.Width) : ((float)decodeSize / info.Height));

                    // decode the bitmap at the nearest size
                    var nearest = new SKImageInfo(supportedScale.Width, supportedScale.Height);
                    var bmp     = SKBitmap.Decode(codec, nearest);

                    // now scale that to the size that we want
                    var realScale = horizontal ? ((double)info.Height / info.Width) : ((double)info.Width / info.Height);

                    SKImageInfo desired;


                    if (horizontal)
                    {
                        desired = new SKImageInfo(decodeSize, (int)(realScale * decodeSize));
                    }
                    else
                    {
                        desired = new SKImageInfo((int)(realScale * decodeSize), decodeSize);
                    }

                    if (bmp.Width != desired.Width || bmp.Height != desired.Height)
                    {
                        if (bmp.Height != bmp.Width)
                        {
                        }
                        var scaledBmp = bmp.Resize(desired, interpolationMode.ToSKFilterQuality());
                        bmp.Dispose();
                        bmp = scaledBmp;
                    }

                    _image = SKImage.FromBitmap(bmp);
                    bmp.Dispose();

                    if (_image == null)
                    {
                        throw new ArgumentException("Unable to load bitmap from provided data");
                    }

                    PixelSize = new PixelSize(_image.Width, _image.Height);

                    // TODO: Skia doesn't have an API for DPI.
                    Dpi = new Vector(96, 96);
                }
        }
示例#2
0
        public ImmutableBitmap(ImmutableBitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode)
        {
            SKImageInfo info   = new SKImageInfo(destinationSize.Width, destinationSize.Height, SKColorType.Bgra8888);
            SKImage     output = SKImage.Create(info);

            src._image.ScalePixels(output.PeekPixels(), interpolationMode.ToSKFilterQuality());

            _image = output;

            PixelSize = new PixelSize(_image.Width, _image.Height);

            // TODO: Skia doesn't have an API for DPI.
            Dpi = new Vector(96, 96);
        }
示例#3
0
        /// <inheritdoc />
        public void DrawBitmap(IRef <IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
        {
            var drawableImage = (IDrawableBitmapImpl)source.Item;
            var s             = sourceRect.ToSKRect();
            var d             = destRect.ToSKRect();

            using (var paint =
                       new SKPaint
            {
                Color = new SKColor(255, 255, 255, (byte)(255 * opacity * _currentOpacity))
            })
            {
                paint.FilterQuality = bitmapInterpolationMode.ToSKFilterQuality();

                drawableImage.Draw(this, s, d, paint);
            }
        }
        public WriteableBitmapImpl(Stream stream, int decodeSize, bool horizontal, BitmapInterpolationMode interpolationMode)
        {
            using (var skStream = new SKManagedStream(stream))
                using (var skData = SKData.Create(skStream))
                    using (var codec = SKCodec.Create(skData))
                    {
                        var info = codec.Info;

                        // get the scale that is nearest to what we want (eg: jpg returned 512)
                        var supportedScale = codec.GetScaledDimensions(horizontal ? ((float)decodeSize / info.Width) : ((float)decodeSize / info.Height));

                        // decode the bitmap at the nearest size
                        var nearest = new SKImageInfo(supportedScale.Width, supportedScale.Height);
                        var bmp     = SKBitmap.Decode(codec, nearest);

                        // now scale that to the size that we want
                        var realScale = horizontal ? ((double)info.Height / info.Width) : ((double)info.Width / info.Height);

                        SKImageInfo desired;


                        if (horizontal)
                        {
                            desired = new SKImageInfo(decodeSize, (int)(realScale * decodeSize));
                        }
                        else
                        {
                            desired = new SKImageInfo((int)(realScale * decodeSize), decodeSize);
                        }

                        if (bmp.Width != desired.Width || bmp.Height != desired.Height)
                        {
                            var scaledBmp = bmp.Resize(desired, interpolationMode.ToSKFilterQuality());
                            bmp.Dispose();
                            bmp = scaledBmp;
                        }

                        _bitmap = bmp;

                        PixelSize = new PixelSize(bmp.Width, bmp.Height);
                        Dpi       = SkiaPlatform.DefaultDpi;
                    }
        }