mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.8 KiB
44 lines
1.8 KiB
namespace ImageSharp.Tests.TestUtilities.ReferenceCodecs
|
|
{
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.IO;
|
|
|
|
using ImageSharp.Formats;
|
|
using ImageSharp.PixelFormats;
|
|
|
|
public class ReferenceDecoder : IImageDecoder
|
|
{
|
|
public static ReferenceDecoder Instance { get; } = new ReferenceDecoder();
|
|
|
|
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
|
|
{
|
|
if (sourceBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
|
|
{
|
|
return SystemDrawingBridge.FromSystemDrawingBitmap<TPixel>(sourceBitmap);
|
|
}
|
|
|
|
using (var convertedBitmap = new System.Drawing.Bitmap(
|
|
sourceBitmap.Width,
|
|
sourceBitmap.Height,
|
|
System.Drawing.Imaging.PixelFormat.Format32bppArgb))
|
|
{
|
|
using (var g = Graphics.FromImage(convertedBitmap))
|
|
{
|
|
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
|
|
g.DrawImage(sourceBitmap, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
|
}
|
|
return SystemDrawingBridge.FromSystemDrawingBitmap<TPixel>(convertedBitmap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|