as there baidu image has protect refer from other site to use.

need download i use request header add referer:http://www.baidu.com

<Window x:Class="WpfApplication1.WindMsg"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WindMsg" Height="300" Width="300" Closing="Window_Closing" Loaded="Window_Loaded">
    <Grid>
        <Image Name="img" Stretch="Uniform" Source="{Binding BitmapImg}"/>
        <Button Content="{Binding Text}" Height="65" HorizontalAlignment="Left" Margin="58,48,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
    </Grid>
</Window>
 public WindMsg()
        {
            InitializeComponent();
            d = new ImageData() { Url = "http://img0.imgtn.bdimg.com/it/u=3028557787,2951839071&fm=15&gp=0.jpg", Text = "test button text" };
            this.DataContext = d;
        }
        ImageData d;
        public class ImageData
        {
            public string Url { get; set; }
            public string Text { get; set; }
            public ImageSource BitmapImg
            {
                get { return GetImageData(); }
                set { }
            }
            BitmapImage GetImageData()
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("Referer", "http://www.baidu.com");
                    Stream stream = wc.OpenRead(Url);
                    BitmapImage b = new BitmapImage();
                    b.BeginInit();
                    b.StreamSource = stream;
                    b.EndInit();
                    return b;
                }
            }
        }

缓冲图片,延迟加载

// Create source
BitmapImage myBitmapImage = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(str, UriKind.Absolute);
// To save significant application memory, set the DecodePixelWidth or  
// DecodePixelHeight of the BitmapImage value of the image source to the desired 
// height or width of the rendered image. If you don't do this, the application will 
// cache the image as though it were rendered as its normal size rather then just 
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 2048;
myBitmapImage.EndInit();
//set image source

WPF bind baidu Image的更多相关文章

  1. WPF Bind 绑定

    原文:WPF Bind 绑定 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/74332515 用过W ...

  2. Wpf 中的DataGrid的Header属性,动态bind时不起作用

    在使用wpf开发软件时,有使用到DataGrid,DataGridTextColumn的Header 属性使用DynamicResource binding,在修改绑定数据源时,header并没有更新 ...

  3. [WPF] How to bind to data when the datacontext is not inherited

    原文:[WPF] How to bind to data when the datacontext is not inherited 原文地址:http://www.thomaslevesque.co ...

  4. WPF开发ArcGis系统时的异常信息: ArcGIS product not specified. You must first bind to an ArcGIS version prior to using any ArcGIS components.

    “System.Runtime.InteropServices.COMException”类型的未经处理的异常在 Arcgis_Test.exe 中发生 其他信息: ArcGIS product no ...

  5. 【WPF】UI虚拟化之------自定义VirtualizingWrapPanel

    原文:[WPF]UI虚拟化之------自定义VirtualizingWrapPanel 前言 前几天QA报了一个关于OOM的bug,在排查的过程中发现,ListBox控件中被塞入了过多的Item,而 ...

  6. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  7. UWP中新加的数据绑定方式x:Bind分析总结

    UWP中新加的数据绑定方式x:Bind分析总结 0x00 UWP中的x:Bind 由之前有过WPF开发经验,所以在学习UWP的时候直接省略了XAML.数据绑定等几个看着十分眼熟的主题.学习过程中倒是也 ...

  8. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

  9. WPF binding 参考

    Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silve ...

随机推荐

  1. 微信小程序< 3 > ~ 微信小程序开源项目合集

    简介 移动开发者想学习微信小程序需要学习一点HTML ,CSS和JS才能够比较快速的上手,参考自己学习Android学习过程,阅读源码是一个很好的方式,所以才收集了一些WeApp的开源项目. awes ...

  2. 使用标准C读取文件遇到的结构体对齐问题及其解决办法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 同事使用标准C库读取文件,发现总是读取不对,让我帮忙看一下. 原来他定义了如下一个结构体: // 定义块的结构 typ ...

  3. tomcat catalina.out日志切割(logrotate)

    简单说明: 1,因为tomcat日志会一直往catalina.out里面输出,所以回到值catalina.out非常大,占用磁盘空间 2,日志非常大,查看日志就需要很长时间. 3,据说catalina ...

  4. SQL Server下ADO.NET 怎么获取数据库SQL语句INSERT,UPDATE,DELETE了多少行数据

    ADO.NET 在发送SQL语句到SQL Server数据库后,怎么知道真正INSERT,UPDATE,DELETE了多少行数据呢? 使用SQL Server内置的全局变量@@ROWCOUNT即可,@ ...

  5. eclipse neon配置tomcat8无法显示默认页面解决方法

    下载对应tomcat8版本到本地后,在eclipse中添加tomcat8的对应目录,输入http://localhost:8080时无法显示tomcat的index.jsp页面(会显示404页面).原 ...

  6. Python通过LDAP验证、查找用户(class,logging)

    定义一个类,用于初始化ldap连接,验证.查找用户等功能 # -*- coding: UTF-8 -*- import sys reload(sys) sys.setdefaultencoding(' ...

  7. ASA 用TFTP 备份配置方法

    一种方法是用ASDM,在菜单样哪项里有一个backup,保存为一个压缩文件rar,恢复也是用ASDM.另一种是用TFTP SERVER 来做,电脑用网线接上ASA,还要把cisco TFTP SERV ...

  8. 【转】Java学习---内存泄露与溢出的区别

    Java内存泄露与溢出的区别 Java内存泄漏就是没有及时清理内存垃圾,导致系统无法再给你提供内存资源(内存资源耗尽): 而Java内存溢出就是你要求分配的内存超出了系统能给你的,系统不能满足需求,于 ...

  9. SHGetFileInfo 报错 异常 问题

    查看代码是否使用了 ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 如果是,换成在每个线程调用 ::CoInitialize(NULL); 真够蛋疼的,查了 ...

  10. beta冲刺————第四天(4/5)

    完善的具体内容: 前端:以下的功能还未完全实现 (1)点击收藏可以收藏入收藏夹 (2)分享操作,意见反馈 后端: 寻找文章来源,像数据库中增添了150篇的新文章.(我们的文章都要求自己内部人员看过,所 ...