Skip to content

Commit

Permalink
Merge pull request #8 from 0xced/ImageSharp
Browse files Browse the repository at this point in the history
Use ImageSharp instead of System.Drawing.Common
  • Loading branch information
SimonCropp committed Sep 25, 2021
2 parents 96d175e + efa0861 commit 42dc5f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/Verify.DocNet/Verify.DocNet.csproj
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 42dc5f1

Please sign in to comment.