private BitmapSource MatToBitmapSource(Mat mat, ref byte[] gray) { PixelFormat pf = PixelFormats.Gray8; int rawStride = (mat.Width * pf.BitsPerPixel + 7) / 8; mat.GetArray(out gray); return BitmapSource.Create(mat.Width, mat.Height, 96, 96, pf, null, gray, rawStride); } private BitmapSource MatToBitmapSource(Mat mat, ref ushort[] gray) { PixelFormat pf = PixelFormats.Gray16; int rawStride = (mat.Width * pf.BitsPerPixel + 7) / 8; mat.GetArray(out gray); return BitmapSource.Create(mat.Width, mat.Height, 96, 96, pf, null, gray, rawStride); }
标签:gray,mat,BitmapSource,Width,opencv,MatToBitmapSource,pf,sharp From: https://www.cnblogs.com/lizhiqiang0204/p/17183521.html