个人资料

跳过导航链接首页 > 博客列表 > 博客正文

Bitmap转BitmapImage(ImageSource)

:

扩展方法


    public static class ext
    {


        public static BitmapImage ToBitmapImage(this Bitmap bitmap)
        {

            var stream = new InMemoryRandomAccessStream();
            bitmap.Save(stream.AsStreamForWrite(), ImageFormat.Png);

            stream.Seek(0);

            BitmapImage bi = new BitmapImage();
            bi.SetSource(stream);


            return bi;

        }



    }



OpenCVSharp

Mat->BitmapImage并显示

            byte[] bytes=mat512.ToBytes();
            using (var ms=new InMemoryRandomAccessStream())
            {
               var bi = new BitmapImage();
               await ms.WriteAsync(bytes.AsBuffer());
               ms.Seek(0);
               await bi.SetSourceAsync(ms);
               img4.Source=bi;
            }

end

songshizhao
最初发表2023/11/28 15:20:40 最近更新2023/11/30 15:11:30 446
为此篇作品打分
10