Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ImageSharp instead of System.Drawing.Common #8

Merged
merged 1 commit into from Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Verify.DocNet/Verify.DocNet.csproj
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Docnet.Core" Version="2.3.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="Verify" Version="11.27.0" />
<PackageReference Include="ProjectDefaults" Version="1.0.58" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />
Expand Down
22 changes: 4 additions & 18 deletions src/Verify.DocNet/VerifyDocNet_Pdf.cs
@@ -1,12 +1,11 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Docnet.Core;
using Docnet.Core.Converters;
using Docnet.Core.Readers;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace VerifyTests
{
Expand Down Expand Up @@ -41,25 +40,12 @@ static IEnumerable<Target> GetStreams(IDocReader document, IReadOnlyDictionary<s
var width = reader.GetPageWidth();
var height = reader.GetPageHeight();

using var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

AddBytes(bitmap, rawBytes);
var image = Image.LoadPixelData<Bgra32>(rawBytes, width, height);

var stream = new MemoryStream();
bitmap.Save(stream, ImageFormat.Png);
image.SaveAsPng(stream);
yield return new("png", stream);
}
}

static void AddBytes(Bitmap bmp, byte[] rawBytes)
{
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

var bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly, bmp.PixelFormat);
var pNative = bmpData.Scan0;

Marshal.Copy(rawBytes, 0, pNative, rawBytes.Length);
bmp.UnlockBits(bmpData);
}
}
}