wpf image source

<Image Name="img" Source=""/>

1:source指向url

url可以是任何一张网络上的图片;

2:source指向本项目的图片地址

pack://application:,,,/images/test.jpg

可以简写为:/images/test.jpg

3:source指向引用项目的图片地址

pack://application:,,,/程序集名称;component/images/test.jpg

可以简写为:/程序集名称;component/images/test.jpg

4:使用c#指定图片

img.Source = new BitmapImage(new Uri(""));

时间: 2025-01-01 10:01:11

wpf image source的相关文章

自己总结一下wpf image source 绑定的几种方式

绝对路径: 代码   BitmapImage image = new BitmapImage(new Uri("E:\\Project\\xxx.png", UriKind.Absolute));   imgName.source = image; xaml:   <Image Name="imgName" SourceE:\\Project\\xxx.png"> 相对路径: 1) :引用其他程序集的资源 <Image Name=&quo

WPF入门教程系列(二) 深入剖析WPF Binding的使用方法

WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProperty)只能拥有一个binding. 这一点可以通过设置binding对象的方法名得知: public static BindingExpressionBase SetBinding( DependencyObject target, DependencyProperty dp, BindingB

20 Interesting WPF Projects on CodePlex

20 Interesting WPF Projects on CodePlex (Some for Silverlight too) Pete Brown - 22 November 2010 In no particular order, here's a selection of interesting and recently maintained WPF projects I've found on CodePlex. This is by no means a complete lis

WPF Image控件的Source属性是一个ImageSource对象

1.固定的图片路径是可以的,如下: <Image Source="../test.png" /> 2.绑定的Path是一个String类型的图片路径,而实际情况它需要的是一个ImageSource,所以只需在前面标记它是一个Path类型的值就OK了! <DataTemplate> <Image Source="{Binding Path= IconPath}" /> </DataTemplate> ----------

WPF的MediaElement指定Source无法播放问题解决

最近学wpf,在使用 MediaElement 指定 Source 进行视频播放时,在源码界面可以正常显示,但运行时控件显示空白. 源码界面如下图:(可正常显示) 运行后如下图所示:(控件位置显示空白) 指定 Source 为视频文件完整路径时可以正常播放. 解决办法为: 将视频文件属性设置为"如果较新则复制"后解决,如下图所示: 修改后,启动运行,问题解决.

WPF Data Binding之控件作为源(Source)与路径(Path)【一】

Binding 的源也就是数据的源头.Binding对源的要求并不苛刻------只要它是一个对象,并且通过属性(Property)公开自己的数据,它就能作为Binding 的源. 前面一个例子已经向大家证明,如果想让作为Binding源的对象具有自动通知Binding自己属性值已经已经变化的能力,那么就需要让类实现INotifyChanged接口并在属性的Set语句中激发PropertyChanged事件.在日常生活中,除了使用这种对象作为数据源之外,我们还有更多的选择,比如用一个控件做为另一

WPF Image控件 Source: Byte[] ,BitmapImage 相互转换

文件转为byte[] FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); byte[] desBytes = new byte[fs.Length]; fs.Read(desBytes, 0, desBytes.Length); fs.Close(); byte[]转换为BitmapImage: public static BitmapImage ByteArrayToBitmapImage(byte

WPF中的image控件的Source赋值

image控件的Source设置为相对路径后(Source="haha.png")运行不能显示 解决方案:当Source设置为相对路径后(Source="haha.png")Visual Studio 2013会在属性栏的Source中生成“/WpfApplication1;component/haha.png”. 不知道在其他Visual Studio中会不会这样,但是可以按照这样写就不会出现不能显示的问题. img.Source = new BitmapImag

如何把drawing图像转换成wpf控件的source

此例以canvas为例 <Canvas>  <Image Stretch="Fill" Width="100" Height="100" x:Name="myImage"/></Canvas> 一种方法:System.Drawing.Image bmp=...; // 自己初始化的有效的 imageSystem.IO.MemoryStream ms = new System.IO.Memor