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. JS--我发现,原来你是这样的JS(二)(基础概念--躯壳篇--不妨从中文角度看js)

    一.介绍 这是红宝书(JavaScript高级程序设计 3版)的读书笔记第二篇(基础概念--躯壳篇),有着部分第三章的知识内容,当然其中还有我个人的理解. 红宝书这本书可以说是难啃的,要看完不容易,挺 ...

  2. iOS8自定义推送显示按钮及推送优化

    http://www.jianshu.com/p/803bfaae989e iOS8自定义推送显示按钮及推送优化 字数1435 阅读473 评论0 喜欢2 导语 在iOS8中,推送消息不再只是简单地点 ...

  3. 排错-SP2-1503:无法初始化Oracle调用界面解决

    SP2-1503:无法初始化Oracle调用界面解决 by:授客 QQ:1033553122 SP2-1503:无法初始化Oracle调用界面解决 问题描述: win7下,cmd运行输入sqlplus ...

  4. 10款jQuery文本高亮插件

    [编者按]本文作者为 Julian Motz,主要介绍十款 jQuery 文本高亮插件的现状.文章系国内 ITOM 管理平台 OneAPM 编译呈现. 很多应用或网站都为用户提供搜索关键词的方法.为了 ...

  5. LeetCode题解之Maximum Depth of N-ary Tree

    1.题目描述 2.问题分析 利用递归fangf 3.代码 int maxDepth(Node* root) { int res = maxdep(root); return res; } int ma ...

  6. jmeter之数据库相关

    一.JDBC Connection Configuration 1.Variable Name Bound to Pool-Variable Name:连接池名称, JDBC Request通过此名称 ...

  7. Distribution setup SQL Server Agent error: "RegCreateKeyEx() returned error 5, 'Access is denied.'" (转载)

    In the Configure Distribution Wizard, the step "Configuring SQL Server Agent to start automatic ...

  8. round()和trunc()用法

    round(数字 | 列 保留小数的位数):四舍五入. select a.*,round(s),round(-s) from bqh4 a trunc(数字 | 列 保留小数的位数):舍弃指定位置的内 ...

  9. [Python_3] Python 函数 & IO

    0. 说明 Python 函数 & IO 笔记,基于 Python 3.6.2 参考  Python: read(), readline()和readlines()使用方法及性能比较  Pyt ...

  10. Java Collection集合方法

    一.简单方法 package cn.itcast.day15; import java.util.ArrayList; import java.util.Arrays; import java.uti ...