WPF动态创建Image的显示问题
2024-10-02 00:01:38
最近学习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容器中
最新文章
- Linux 下dns的搭建
- Unity.Interception(AOP)
- jQuery操作select控件取值和设值
- [转]JSON 入门指南
- hdu 4635 Strongly connected
- mysql 索引优化
- 【docker】docker初试与填坑
- oracle体系结构
- linux 控制台使用技巧
- linux远程登录ssh免密码
- Window7下安装Jmeter
- PyCharm Debug 调试
- vim小技巧2
- crontab在/var/log/目录下没有cron.log文件
- Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
- 用C#中的键值对遍历数组或字符串元素的次数
- ORACLE 表空间扩展方法
- 【java】详解JFrame结构的分层
- 每天学一点easyui①
- Linux下文件的打包、解压缩指令——tar,gzip,bzip2