积极答复者
In wpf ,how to complement image fit to window and show in actual size

问题
-
<Image Source="{Binding ImageSource}"/>
here it shows should be actual size , how can i make it to fit to window size,OpenFileDialog ofdimg=new OpenFileDialog(); ofdimg.Filter = "Image Files (*.jpg;*.jpep)|*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.gif;|All Files (*.*)|*.*"; ofdimg.ShowDialog(); string ImgPath = ofdimg.FileName; BitmapSource bm = new BitmapImage(new Uri(ImgPath)); ImageSource = bm;
BitmapImage mybm = new BitmapImage();
mybm.BeginInit();
mybm.UriSource = new Uri(ImgPath);
mybm.DecodePixelWidth = bm.PixelWidth;//actual size
mybm.EndInit();
ImageSource = mybm;- 已编辑 Rogerguo 2015年2月2日 3:46
答案
-
你好,
我们可以使用 ScaleTransform 去实现缩放效果,ScaleX和ScaleY可以绑定到Slider的Value:
<Image Source="{Binding ImageSource}"> <Image.RenderTransform> <ScaleTransform x:Name="scale" ScaleX="{Binding Value, ElementName=slider1}" ScaleY="{Binding Value, ElementName=slider1}" CenterX="0.5" CenterY="0.5"/> </Image.RenderTransform> </Image> <Slider Grid.Row="1" Name="slider1" Maximum="1" Minimum="0" Value="1" TickPlacement="Both" />
截图:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2015年2月13日 15:04
全部回复
-
你好,
我们可以使用 ScaleTransform 去实现缩放效果,ScaleX和ScaleY可以绑定到Slider的Value:
<Image Source="{Binding ImageSource}"> <Image.RenderTransform> <ScaleTransform x:Name="scale" ScaleX="{Binding Value, ElementName=slider1}" ScaleY="{Binding Value, ElementName=slider1}" CenterX="0.5" CenterY="0.5"/> </Image.RenderTransform> </Image> <Slider Grid.Row="1" Name="slider1" Maximum="1" Minimum="0" Value="1" TickPlacement="Both" />
截图:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2015年2月13日 15:04
-
谢谢,如果要调整image适应窗口大小的话,应该先获得窗口的size,然后保持图片的比例,调整到slider合适的值,是这样的吗?wpf中有类似的可以实现的方法吗?就像你上面一样可以不用后台代码, 比如调整image的stretch属性
你好,
>>如果要调整image适应窗口大小的话,应该先获得窗口的size,然后保持图片的比例,调整到slider合适的值,是这样的吗?wpf中有类似的可以实现的方法吗?就像你上面一样可以不用后台代码, 比如调整image的stretch属性
默认Image控件的Stretch属性为 Uniform,如果你调整窗口大小,让Image控件自动调整大小的话,是可以发现图片能自适应的。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.