opencv sharp MatToBitmapSource

        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);
        }

 

posted @ 2023-03-06 13:27  阿坦  阅读(91)  评论(0)    收藏  举报