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

时间: 2024-08-09 13:27:09

WPF:How to display a Bitmap on Image control的相关文章

WPF中的Generic.xaml, theme以及custom control

原文:WPF中的Generic.xaml, theme以及custom control 在Visual Studio中创建自定义控件时,所有控件都将添加到/Themes/Generic.xaml. 最近做的项目用了个漂亮的开源UI库,结果项目临近结尾发现要支持.Net 3.5, 然而那个UI库却最低支持4.0.欲哭无泪,最后决定拿掉那个库,自己改改style得了.深刻的教训. 作为程序员一般都比较害怕搞界面,这下硬着头皮上,折腾折腾Blend,抄抄改改各种style,弄着弄着居然能看懂个大概了.

Wpf开源收集

1,到底有哪些开源MVVM框架? 前面介绍了WPF的基本概念和一些相关知识,我们了解到开发WPF应用程序可以使用现成的框架和模式,最为合适的莫过于时下正热的MVVM模式,所以这里我们也列出针对MVVM模式的已有开源框架: 图3 上面除了WPFToolKit和MEF之外都是一些常用的MVVM框架,连带自己开发的一共是八个,所以自己也取了一个响亮的名字——MVVM 八大框架!圣殿骑士本人实际项目中只用到了三个框架,之前WPF使用过MVVM Helpers,在Silverlight项目当中用过MVVM

WPF工具开发: 第三库选择

PropertyGrid Winforms's PropertyGrid 非WPF原生支持, 需要借助WinFormHost 风格不可定制 PropertyInspectorView 算是"官方"库, 风格不可定制 WPF Property Grid 开源 功能还不够完善 可以定制风格 PropertyEditor for WPF 开源 功能比较实用, 有自己的特色 Actipro PropertyGrid 商业控件 Mindscape WPF Property Grid 商业控件 D

使用 WPF 创建预加载控件

Introduction At the time when WPF applications do a very long process like getting response from a web server, download file from a distant server, search files, etc., this control can be used to make the wait time more interactive. This is an altern

Linux 如何解决 xhost: unable to open display ""

[[email protected] ~]# vncservice You will require a password to access your desktops. Password: Verify: xauth: creating new authority file /root/.Xauthority New 'host02:1 (root)' desktop is host02:1 #我没设置过密码 这里需要设置密码 [[email protected] ~]# export DI

WPF - 属性系统 (4 of 4)

依赖项属性的重写 在基于C#的编程中,对属性的重写常常是一种行之有效的解决方案:在基类所提供的属性访问符实现不能满足当前要求的时候,我们就需要重新定义属性的访问符. 但对于依赖项属性而言,属性执行逻辑的重新定义并不能存在于CLR属性包装中:WPF内部对依赖项属性的实现要求依赖项属性的CLR包装实现仅仅调用GetValue()以及SetValue()属性,而不能提供其它的自定义逻辑.相反地,我们需要通过更改创建时所传入的元数据来指定自定义属性执行逻辑,甚至在某些更苛刻的要求下,如更改依赖项属性的类

WPF模板

1:ControlTemplate 我们知道wpf的控件都是继承自Control,在Control类中有一个Template属性,类型就是ControlTemplate.那么利用这个ControlTemplate就可以彻底的颠覆控件的默认外观. <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x

Display controller

Field of the Invention The present invention relates to a display controller. Background to the invention Display controllers are known. One such display controller 10 is shown in the display system, generally 5, illustrated by figure 1. A display 40

[WPF自定义控件]从ContentControl开始入门自定义控件

原文:[WPF自定义控件]从ContentControl开始入门自定义控件 1. 前言 我去年写过一个在UWP自定义控件的系列博客,大部分的经验都可以用在WPF中(只有一点小区别).这篇文章的目的是快速入门自定义控件的开发,所以尽量精简了篇幅,更深入的概念在以后介绍各控件的文章中实际运用到才介绍. ContentControl是WPF中最基础的一种控件,Window.Button.ScrollViewer.Label.ListBoxItem等都继承自ContentControl.而且Conten