예제 #1
0
 public static bool ToImage(this SkiaSharp.SKPicture skPicture, Stream stream, SkiaSharp.SKColor background, SkiaSharp.SKEncodedImageFormat format, int quality, float scaleX, float scaleY, SkiaSharp.SKColorType skColorType, SkiaSharp.SKAlphaType skAlphaType, SkiaSharp.SKColorSpace skColorSpace)
 {
     using var skBitmap = skPicture.ToBitmap(background, scaleX, scaleY, skColorType, skAlphaType, skColorSpace);
     if (skBitmap is null)
     {
         return(false);
     }
     using var skImage = SkiaSharp.SKImage.FromBitmap(skBitmap);
     using var skData  = skImage.Encode(format, quality);
     if (skData is { })
예제 #2
0
        public static SkiaSharp.SKBitmap?ToBitmap(this SkiaSharp.SKPicture skPicture, SkiaSharp.SKColor background, float scaleX, float scaleY, SkiaSharp.SKColorType skColorType, SkiaSharp.SKAlphaType skAlphaType, SkiaSharp.SKColorSpace skColorSpace)
        {
            var width  = skPicture.CullRect.Width * scaleX;
            var height = skPicture.CullRect.Height * scaleY;

            if (!(width > 0) || !(height > 0))
            {
                return(null);
            }
            var skImageInfo = new SkiaSharp.SKImageInfo((int)width, (int)height, skColorType, skAlphaType, skColorSpace);
            var skBitmap    = new SkiaSharp.SKBitmap(skImageInfo);

            using var skCanvas = new SkiaSharp.SKCanvas(skBitmap);
            Draw(skPicture, background, scaleX, scaleY, skCanvas);
            return(skBitmap);
        }