public Stream MatToStream(Mat m) { using (var vect = new MatOfByte()) { if (Imgcodecs.Imencode(".png", m, vect)) { var stream = new MemoryStream(vect.ToArray()); return(stream); } return(null); } }