refactored

This commit is contained in:
Manuel Kamper 2019-04-20 15:51:50 +02:00
parent 779efaf223
commit 91487b85af
2 changed files with 32 additions and 7 deletions

View File

@ -1,14 +1,16 @@
using System.IO; using System.Drawing;
using System.IO;
namespace Mk0.Tools.Convert namespace Mk0.Tools.Convert
{ {
public static class ByteConvert public static class ByteConvert
{ {
public static System.Drawing.Image ToImage(this byte[] byteArrayIn) public static Image ToImage(this byte[] byteArray)
{ {
MemoryStream ms = new MemoryStream(byteArrayIn); using (MemoryStream ms = new MemoryStream(byteArray))
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms); {
return returnImage; return Image.FromStream(ms);
}
} }
} }
} }

View File

@ -1,14 +1,37 @@
using System.IO; using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Mk0.Tools.Convert namespace Mk0.Tools.Convert
{ {
public static class ImageConvert public static class ImageConvert
{ {
public static byte[] ToByte(this System.Drawing.Image imageIn) public static byte[] ToByte(this Image image)
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); image.Save(ms, ImageFormat.Gif);
return ms.ToArray(); return ms.ToArray();
} }
public static byte[] ToByte(this Image image, string extension)
{
using (var ms = new MemoryStream())
{
switch (extension)
{
case ".jpeg":
case ".jpg":
image.Save(ms, ImageFormat.Jpeg);
break;
case ".png":
image.Save(ms, ImageFormat.Png);
break;
case ".gif":
image.Save(ms, ImageFormat.Gif);
break;
}
return ms.ToArray();
}
}
} }
} }