-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd7a8d
commit 1aecb22
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Wiesław Šoltés. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
using SkiaSharp; | ||
|
||
namespace Svg.Skia | ||
{ | ||
public static class SkiaExtensions | ||
{ | ||
public static SKBitmap? ToBitmap(this SKPicture skPicture, SKColor background, float scaleX, float scaleY) | ||
{ | ||
float width = skPicture.CullRect.Width * scaleX; | ||
float height = skPicture.CullRect.Height * scaleY; | ||
if (width > 0 && height > 0) | ||
{ | ||
var skImageInfo = new SKImageInfo((int)width, (int)height); | ||
var skBitmap = new SKBitmap(skImageInfo); | ||
using (var skCanvas = new SKCanvas(skBitmap)) | ||
{ | ||
skCanvas.Clear(SKColors.Transparent); | ||
if (background != SKColor.Empty) | ||
{ | ||
skCanvas.DrawColor(background); | ||
} | ||
skCanvas.Save(); | ||
skCanvas.Scale(scaleX, scaleY); | ||
skCanvas.DrawPicture(skPicture); | ||
skCanvas.Restore(); | ||
return skBitmap; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |