mirror of
https://github.com/DarthAffe/HPPH.git
synced 2026-11-09 18:36:34 +00:00
Fixed a lot of isssues brought up by the analyzers
This commit is contained in:
1 parent
cddb82e07e
commit
b66fc3c9e9
24 files changed
+230
-36
No files matched your search
@@ -44,6 +44,10 @@
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<GlobalAnalyzerConfigFiles Include="../Analyzers.globalconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -9,6 +9,8 @@ public static class ImageExtension
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static unsafe Bitmap ToBitmap(this IImage image)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(image, nameof(image));
|
||||
|
||||
switch (image.ColorFormat.BytesPerPixel)
|
||||
{
|
||||
case 3:
|
||||
@@ -57,6 +59,8 @@ public static class ImageExtension
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static byte[] ToPng(this IImage image)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(image, nameof(image));
|
||||
|
||||
using Bitmap bitmap = ToBitmap(image);
|
||||
using MemoryStream ms = new();
|
||||
bitmap.Save(ms, ImageFormat.Png);
|
||||
@@ -67,6 +71,8 @@ public static class ImageExtension
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static unsafe IImage ToImage(this Bitmap bitmap)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(bitmap, nameof(bitmap));
|
||||
|
||||
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
ReadOnlySpan<byte> buffer = new(data.Scan0.ToPointer(), data.Stride * data.Height);
|
||||
|
||||
|
||||
Reference in new issue
Block a user