Squirrowse/Squirrowse.Core/Services/ImgExtensions.cs
danielgrabowski 3de1b04cb4 + common packages
+ Tests for common core
2019-10-31 17:00:52 +01:00

21 lines
617 B
C#

using System.Linq;
using System.Runtime.CompilerServices;
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)
{
using var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
return tempMat ?? new Mat();
}
}
}