zoukankan      html  css  js  c++  java
  • WPF:How to display a Bitmap on Image control

    一个Bitmap文件,叫做screenShotFile, 你可以这样显示到Image控件上。

                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(this.screenShotFile, UriKind.Absolute);
                bi.EndInit();
                this.screenshotImage.Source = bi;

    但是有个问题,这个文件你无法删除,会报错说“另一个进程正在使用”。什么鬼?是bug吗?

    如果你的Bitmap还在内存里,这个问题就比较好解决了:

                BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(this.bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height));
                this.screenshotImage.Source = bs;

    其中,Imaging的namespace是这个:namespace System.Windows.Interop

  • 相关阅读:
    form标签
    roadmap
    自我介绍
    3 week work—Grid Layout
    3 week work—Position
    2nd week
    objects
    个人简介
    7th week :DOM BOM
    颜色表示法
  • 原文地址:https://www.cnblogs.com/ms-uap/p/7202206.html
Copyright © 2011-2022 走看看