mirror of https://github.com/SixLabors/ImageSharp
5 changed files with 155 additions and 3 deletions
@ -0,0 +1,31 @@ |
|||||
|
namespace ImageSharp.Tests.TestUtilities.Integration |
||||
|
{ |
||||
|
using System; |
||||
|
using System.IO; |
||||
|
|
||||
|
using ImageSharp.Formats; |
||||
|
using ImageSharp.PixelFormats; |
||||
|
|
||||
|
public class ReferencePngDecoder : IImageDecoder |
||||
|
{ |
||||
|
public static ReferencePngDecoder Instance { get; } = new ReferencePngDecoder(); |
||||
|
|
||||
|
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (var sdBitmap = new System.Drawing.Bitmap(stream)) |
||||
|
{ |
||||
|
if (!sdBitmap.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png)) |
||||
|
{ |
||||
|
throw new Exception("Reference image should be a Png!"); |
||||
|
} |
||||
|
if (sdBitmap.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) |
||||
|
{ |
||||
|
throw new Exception("Reference image pixel format should be PixelFormat.Format32bppArgb!"); |
||||
|
} |
||||
|
|
||||
|
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(sdBitmap); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace ImageSharp.Tests.TestUtilities.Integration |
||||
|
{ |
||||
|
using System.IO; |
||||
|
|
||||
|
using ImageSharp.Formats; |
||||
|
using ImageSharp.PixelFormats; |
||||
|
|
||||
|
public class ReferencePngEncoder : IImageEncoder |
||||
|
{ |
||||
|
public static ReferencePngEncoder Instance { get; } = new ReferencePngEncoder(); |
||||
|
|
||||
|
public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (System.Drawing.Bitmap sdBitmap = IntegrationTestUtils.ToSystemDrawingBitmap(image)) |
||||
|
{ |
||||
|
sdBitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue