20 lines
574 B
C#
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();
|
|
}
|
|
}
|
|
} |