-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathSkiaSharpAdditionalTests.cs
More file actions
99 lines (93 loc) · 3.06 KB
/
Copy pathSkiaSharpAdditionalTests.cs
File metadata and controls
99 lines (93 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.IO;
using FluentAssertions;
using MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes;
using PdfSharpCore.Drawing;
using PdfSharpCore.Test.Helpers;
using PdfSharpCore.Utils;
using SkiaSharp;
using Xunit;
namespace PdfSharpCore.Test
{
public class SkiaSharpAdditionalTests
{
public SkiaSharpAdditionalTests()
{
ImageSource.ImageSourceImpl = new SkiaSharpImageSource();
}
[Fact]
public void FromBinaryLoadsImage()
{
var path = PathHelper.GetInstance().GetAssetPath("lenna.png");
var bytes = File.ReadAllBytes(path);
var src = ImageSource.FromBinary("lenna", () => bytes);
try
{
src.Width.Should().BeGreaterThan(0);
src.Height.Should().BeGreaterThan(0);
}
finally
{
(src as IDisposable)?.Dispose();
}
}
[Fact]
public void SaveAsJpegQualityAffectsSize()
{
using var bmp = new SKBitmap(new SKImageInfo(50, 50));
using (var canvas = new SKCanvas(bmp))
{
canvas.DrawColor(SKColors.Orange);
canvas.Flush();
}
var low = SkiaSharpImageSource.FromBitmap(bmp.Copy(), 10);
var high = SkiaSharpImageSource.FromBitmap(bmp.Copy(), 90);
try
{
using var lowMs = new MemoryStream();
using var highMs = new MemoryStream();
low.SaveAsJpeg(lowMs);
high.SaveAsJpeg(highMs);
highMs.Length.Should().BeGreaterThan(lowMs.Length);
}
finally
{
(low as IDisposable)?.Dispose();
(high as IDisposable)?.Dispose();
}
}
[Fact]
public void XImageFromImageSourceHasPixelDimensions()
{
using var bmp = new SKBitmap(new SKImageInfo(40, 50, SKColorType.Bgra8888, SKAlphaType.Premul));
var src = SkiaSharpImageSource.FromBitmap(bmp.Copy());
try
{
using var img = XImage.FromImageSource(src);
img.PixelWidth.Should().Be(40);
img.PixelHeight.Should().Be(50);
}
finally
{
(src as IDisposable)?.Dispose();
}
}
[Fact]
public void FromFileInitializesSkiaSharpImageSource()
{
var previous = ImageSource.ImageSourceImpl;
try
{
ImageSource.ImageSourceImpl = null;
var path = PathHelper.GetInstance().GetAssetPath("lenna.png");
using var img = XImage.FromFile(path);
ImageSource.ImageSourceImpl.Should().BeOfType<SkiaSharpImageSource>();
img.PixelWidth.Should().BeGreaterThan(0);
}
finally
{
ImageSource.ImageSourceImpl = previous ?? new SkiaSharpImageSource();
}
}
}
}