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. Just write about

    创建一个学生对象,存储学生对象,学生对象的数据来源于键盘录入,最后遍历集合. 学生类,集合对象,键盘录入数据并将数据赋值给学生类的成员(可以写成一个方法),调用方法,遍历集合.

  2. Chrome下解决本地异步请求失败的问题(Origin null is not allowed by Access-Control-Allow-Origin. )

    Chrome更新版本后发现打开本地Jquery easyui没有数据,查看控制台才发现如下问题解决的办法是设置启动参数"--allow-file-access-from-files" ...

  3. LeetCode题解之Max Consecutive Ones

    1.题目描述 2.问题分析 遍历一次数组,以每个1 为起点向后数,数到0 时比较当前1的个数和最大1 的个数,然后将遍历的起点放到当前0 的后面. 3.代码 int findMaxConsecutiv ...

  4. Oracle EBS AP 供应商API

    --创建供应商地址上的电话号码 created by jenrry 20170419 DECLARE l_return_status VARCHAR2(1); l_msg_count NUMBER; ...

  5. python之绘制图形库turtle

    关于绘制图形库turtle# 画布上,默认有一个坐标原点为画布中心的坐标轴(0,0),默认"standard"模式坐标原点上有一只面朝x轴正方向小乌龟 一:海龟箭头Turtle相关 ...

  6. MySQL索引与Index Condition Pushdown(employees示例)

    实验 先从一个简单的实验开始直观认识ICP的作用. 安装数据库 首先需要安装一个支持ICP的MariaDB或MySQL数据库.我使用的是MariaDB 5.5.34,如果是使用MySQL则需要5.6版 ...

  7. 学习笔记:Rick's RoTs -- Rules of Thumb for MySQL

    Table of Contents SELECTs -- do's and don'tsINDEXingENGINE DifferencesOptimizations, and notPARTITIO ...

  8. rsync 数据同步

    什么是Rsync? Rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地货远程数据同步备份的优秀工具.适用于unix/linux/windows等多种操作系统平台. Rsync具有可使本地 ...

  9. 事务的ACID性质

    最近在读黄健宏的<Redis设计与实现>,现在看到了事务这章,由于之前(上学)没有好好整理过数据库事务的四大性质,导致现在(工作)看到了就和第一次知道一样((lll¬ω¬)).还是要把基础 ...

  10. Qt: QSqlRecord字段值为null时注意事项

    QSqlRecord在对应字段值为null时,QSqlRecord::value返回的QVariant是有效但为null(相当于使用QVariant(Type type)构造的),所以此时做对应类型的 ...