3de1b04cb4
+ Tests for common core
21 lines
617 B
C#
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();
|
|
}
|
|
}
|
|
} |