|
using SixLabors.ImageSharp; |
|
using SixLabors.ImageSharp.Formats; |
|
using SixLabors.ImageSharp.Formats.Jpeg; |
|
using System.Drawing.Imaging; |
|
using Image = SixLabors.ImageSharp.Image; |
|
|
|
namespace PNGMetadataViewer |
|
{ |
|
internal static class ImageExtensions |
|
{ |
|
#region Public Methods |
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] ToArray(this SixLabors.ImageSharp.Image imageIn) |
|
{ |
|
using (MemoryStream ms = new MemoryStream()) |
|
{ |
|
imageIn.Save(ms, JpegFormat.Instance); |
|
return ms.ToArray(); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] ToArray(this SixLabors.ImageSharp.Image imageIn, IImageFormat fmt) |
|
{ |
|
using (MemoryStream ms = new MemoryStream()) |
|
{ |
|
imageIn.Save(ms, fmt); |
|
return ms.ToArray(); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] ToArray(this global::System.Drawing.Image imageIn) |
|
{ |
|
return ToArray(imageIn, ImageFormat.Png); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] ToArray(this global::System.Drawing.Image imageIn, ImageFormat fmt) |
|
{ |
|
using (MemoryStream ms = new MemoryStream()) |
|
{ |
|
imageIn.Save(ms, fmt); |
|
return ms.ToArray(); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Image ToImage(this byte[] byteArrayIn) |
|
{ |
|
using (MemoryStream ms = new MemoryStream(byteArrayIn)) |
|
{ |
|
Image returnImage = Image.Load(ms); |
|
return returnImage; |
|
} |
|
} |
|
|
|
public static global::System.Drawing.Image ToNetImage(this byte[] byteArrayIn) |
|
{ |
|
using (MemoryStream ms = new MemoryStream(byteArrayIn)) |
|
{ |
|
global::System.Drawing.Image returnImage = global::System.Drawing.Image.FromStream(ms); |
|
return returnImage; |
|
} |
|
} |
|
|
|
#endregion Public Methods |
|
} |
|
} |
|
|