-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathImageFileOptimizationResult.cs
More file actions
50 lines (41 loc) · 1.36 KB
/
ImageFileOptimizationResult.cs
File metadata and controls
50 lines (41 loc) · 1.36 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
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace DotNetCampus.MediaConverters.Imaging.Optimizations;
/// <summary>
/// 图片文件优化结果
/// </summary>
public readonly record struct ImageFileOptimizationResult() : IDisposable
{
/// <summary>
/// 优化后的图片文件
/// </summary>
public required FileInfo? OptimizedImageFile { get; init; }
public Exception? Exception { get; init; }
public ImageFileOptimizationFailureReason FailureReason { get; init; } = ImageFileOptimizationFailureReason.Ok;
public bool IsSuccess => OptimizedImageFile is not null || Image is not null;
public Image<Rgba32>? Image { get; init; }
public void Dispose()
{
Image?.Dispose();
}
public static ImageFileOptimizationResult FailException(Exception e)
{
return new ImageFileOptimizationResult()
{
OptimizedImageFile = null,
Exception = e,
FailureReason = ImageFileOptimizationFailureReason.Exception
};
}
public static ImageFileOptimizationResult NotSupported()
{
return new ImageFileOptimizationResult()
{
OptimizedImageFile = null,
FailureReason = ImageFileOptimizationFailureReason.NotSupported
};
}
}