Squirrowse/Squirrowse.Core/Services/ImgExtensions.cs
2019-11-05 10:30:31 +01:00

20 lines
574 B
C#

using System.Linq;
using OpenCvSharp;
namespace Squirrowse.Core.Services
{
public static class ImgExtensions
{
public static byte[] ConvertToJpgByte(this Mat mat)
{
Cv2.ImEncode(".jpg", mat, out var imgbuffer); //no need to dispose
return imgbuffer.Any() ? imgbuffer : new byte[] { };
}
public static Mat ConvertByteToMat(this byte[] bytearr)
{
var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
return tempMat ?? new Mat();
}
}
}