《wpf/XAML--在客户端浏览数据库查询出来的图片》

DataRowView // 表示 System.Data.DataRow 的自定义视图。
我们点击表格时把一行数据传输过来了。

调用服务端的方法之前需要实例化服务端对象
BLL.UC_StaffInformation.UC_StaffInformationClient dbs = new BLL.UC_StaffInformation.UC_StaffInformationClient();
下面调用了方法
myPictureByte = dbs.Click_SelectAppDomain();

  public string Click_SelectAppDomain()
    {
        return System.AppDomain.CurrentDomain.BaseDirectory;
    }
    我这里只是传输一个获取了应用基程序的路径;

然后拼接 myPictureByte = myPictureByte + “image\” + strOldPath;

当图片存在的时候,就调用一个方法转换一下图片的类型,使图片可以使用Source属性来添加

  BitmapImage images;
            if (strOldPath != "")
            {
                images = GetImage(myPictureByte);
            }
            else
            {
                images = new BitmapImage(new Uri(("E:\\wpf\\项目Service+Client\\TTS_Service\\WcfService\\image\\noimg.png").ToString()));
            }
            img_photo.Source = images;
           
       我们需要使用使用下面的方法,这样可以释放图片的资源,不会一直占用着图片的资源,
       不然当修改图片的时候会无法删原来的图片;
  public static BitmapImage GetImage(string imagePath)
        {
            BitmapImage bitmap = new BitmapImage();

            if (File.Exists(imagePath))
            {
                bitmap.BeginInit();
                bitmap.CacheOption = BitmapCacheOption.OnLoad;

                using (Stream ms = new MemoryStream(File.ReadAllBytes(imagePath)))
                {
                    bitmap.StreamSource = ms;
                    bitmap.EndInit();
                    bitmap.Freeze();
                }
            }

            return bitmap;
        }
        ~~~~~~~~~~~~~~~~~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值