35 lines
887 B
C#
35 lines
887 B
C#
using System;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
|
|
namespace DeviceRepair.Utils
|
|
{
|
|
public static class IOExtend
|
|
{
|
|
public static byte[] ImageToByteArray(this Image image)
|
|
{
|
|
try
|
|
{
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
return ms.ToArray();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static byte[] FileToByteArray(string filePath)
|
|
{
|
|
FileStream files = new FileStream(filePath, FileMode.Open);
|
|
byte[] ByteData = new byte[files.Length];
|
|
files.Read(ByteData, 0, ByteData.Length);
|
|
files.Close();
|
|
return ByteData;
|
|
}
|
|
}
|
|
}
|