原文:WPF动态创建Image的显示问题

最近学习WPF,看到一篇教程讲解如何动态创建Image控件,自己练手时候无论如何也显示不出图片。刚开始以为是图片的路径有问题,可后来将图片的路径设为相对路径或者绝对路径都没有解决问题。于是开始在网上搜索资料,直到发现一篇问答《WPF用Image显示图片失误(为啥显示不出来)》,才从回答中找出答案,直接贴代码:

编程环境:VS2012

            BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri("Resource/0.png", UriKind.RelativeOrAbsolute);
bi.EndInit();
bi.Freeze(); Image image = new Image();
image.Source = bi; image.Width = imageWidth; //设置图片宽度
image.Height = imageHeight; //设置图片高度
image.SetValue(Canvas.LeftProperty, imageLeft); //设置图片x坐标
image.SetValue(Canvas.TopProperty, imageTop); //设置图片y坐标
canvas_main.Children.Add(image); //将图片添加到canvas容器中

最新文章

  1. Linux 下dns的搭建
  2. Unity.Interception(AOP)
  3. jQuery操作select控件取值和设值
  4. [转]JSON 入门指南
  5. hdu 4635 Strongly connected
  6. mysql 索引优化
  7. 【docker】docker初试与填坑
  8. oracle体系结构
  9. linux 控制台使用技巧
  10. linux远程登录ssh免密码
  11. Window7下安装Jmeter
  12. PyCharm Debug 调试
  13. vim小技巧2
  14. crontab在/var/log/目录下没有cron.log文件
  15. Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  16. 用C#中的键值对遍历数组或字符串元素的次数
  17. ORACLE 表空间扩展方法
  18. 【java】详解JFrame结构的分层
  19. 每天学一点easyui①
  20. Linux下文件的打包、解压缩指令——tar,gzip,bzip2

热门文章

  1. 洛谷——P1089 津津的储蓄计划
  2. Let's do our own full blown HTTP server with Netty--转载
  3. SVGALib
  4. 9.3 Binder系统_驱动情景分析_服务获取过程
  5. stm32的ADC外设地址设置算法
  6. Chrome 临时目录
  7. 6、USB Video Class Specification
  8. 【u247】生物进化
  9. 数据类型总结——Number(数值类型)
  10. Java提高:采用异常链传递异常