如何使用C#的WPF显示图像控制位图图像 [英] How to display Bitmap Image in image control on WPF using C#

查看:801
本文介绍了如何使用C#的WPF显示图像控制位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当我双击一个行的ListView ,它应该显示图片对应于行。该行还包含图片的路径。

I want that when I double click on a row in ListView, it should display the Image corresponding to that row. This row also contains the path of the Image.

我试过以下,但显示相同的图片所有行,因为我已经给了一个具体的路径图片

I tried the following but it displays the same Image for all rows because I have given the path for a specific Image:

private void ListViewEmployeeDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    ImageSource imageSource = new BitmapImage(new Uri(@"C:\northwindimages\king.bmp"));
    image1.Source = imageSource;
}

请建议什么的。

推荐答案

他们关键是要找回被点击的行索引,并获得该行的图像的URL。既然你说你是点击行,这可以在一个方法来实现类似于以下

They key is to retrieve the row index that was clicked, and get the image URL for that row. Since you say you are clicking on the row, this can be done in a method similar to that below

private void ListViewEmployeeDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
    {
    	DataRow row = (DataRow)sender; //Get the row that was clicked
    	string imageURL = row["imageUrl"].ToString();//Get the img URL for that row
    	ImageSource imageSource = new BitmapImage(new Uri(imageURL));
    	image1.Source = imageSource; 
    }

希望这有助于

这篇关于如何使用C#的WPF显示图像控制位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆