WPF Image 显示图片问题

zq1564171310 2014-09-17 08:06:18
期望效果:当图片大小小于控件大小,stretch为none,否则为Uniform(控件大小固定)

...全文
689 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunny906 2014-09-22
  • 打赏
  • 举报
回复
改一下

            BitmapImage source = new BitmapImage(new Uri(@"E:\资料\图片\apic5295_s.jpg"));
            if (source.Width <= this.image.Width && source.Height <= this.image.Height)
            {
                this.image.Stretch = Stretch.None;
            }
            else
            {
                this.image.Stretch = Stretch.Uniform;
            }
            this.image.Source = source;
sunny906 2014-09-22
  • 打赏
  • 举报
回复

            BitmapImage source = new BitmapImage(new Uri(@"图片路径"));
            if (source.Width < this.image.Width || source.Height < this.image.Height)
            {
                this.image.Stretch = Stretch.None;
            }
            else
            {
                this.image.Stretch = Stretch.Uniform;
            }
            this.image.Source = source;
zq1564171310 2014-09-22
  • 打赏
  • 举报
回复
有大虾吗?求助!别沉了
zq1564171310 2014-09-22
  • 打赏
  • 举报
回复
谢谢了,大虾!已结贴!
zq1564171310 2014-09-19
  • 打赏
  • 举报
回复
 if (photo.ActualHeight > this.Height)
            {
                photo.Stretch = Stretch.Uniform;
                photo.Height = this.Height;
            }
            else
            {
                photo.Stretch = Stretch.None;
            }
            if (photo.ActualWidth > this.Width)
            {
                photo.Stretch = Stretch.Uniform;
                photo.Width = this.Width;
            }
            else
            {
                photo.Stretch = Stretch.None;
            }
这样虽然可以做到,但是第一次点击时还是大过,下一张图片才会起效果,没有达到预期效果

13,347

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET技术前瞻
社区管理员
  • .NET技术前瞻社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧