Squirrowse/Squirrowse.Core/Services/ImgExtensions.cs
danielgrabowski 507e08ab19 Codecleamup
2019-11-06 13:47:00 +01:00

20 lines
573 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();
}
}
}