-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for missing PNG compression in SkiaSharp 3.x
- Loading branch information
Showing
10 changed files
with
72 additions
and
28 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
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
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
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
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,28 @@ | ||
using SkiaSharp; | ||
using System; | ||
using System.IO; | ||
|
||
namespace PDFtoImage.Internals | ||
{ | ||
internal static class SKBitmapExtensions | ||
{ | ||
[Obsolete("This is a workaround for the missing PNG compression in SkiaSharp 3.x. Remove this once SkiaSharp is fixed.")] | ||
public static bool EncodeExt(this SKBitmap bitmap, Stream dst, SKEncodedImageFormat format, int quality) | ||
{ | ||
if (format == SKEncodedImageFormat.Png) | ||
{ | ||
using var pixmap = new SKPixmap(bitmap.Info, bitmap.GetPixels()); | ||
using var data = pixmap.Encode(SKPngEncoderOptions.Default); | ||
|
||
if (data == null) | ||
return false; | ||
|
||
data.SaveTo(dst); | ||
|
||
return true; | ||
} | ||
|
||
return bitmap.Encode(dst, format, quality); | ||
} | ||
} | ||
} |
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
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
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
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
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