在WPF应用程序中显示一个巨大的图像

时间:2012-09-05 09:16:40

标签: wpf image

我希望在我的WPF应用程序中显示高清大小的1920X1080图像。当我在图像控件中设置图像源时,只显示部分图像,图像控件的大小。

我不希望将高清图像自动调整到图像控件中。假设图像控制尺寸为640 X 480,则应显示640X480的高清图像。但是当我平移图像时,应显示下一个640 X 480的图像。 我已经实现了TransformGroup  TransformGroup group = new TransformGroup();             ScaleTransform xform = new ScaleTransform();             group.Children.Add(XForm的);             TranslateTransform tt = new TranslateTransform();             group.Children.Add(TT);

但我的问题是最初没有加载整个图像。

2 个答案:

答案 0 :(得分:0)

如果你想要的只是能够滚动你的图像...然后使用:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Visible">
            <Image Stretch="None" Source="c:\mytestimage.png" />
        </ScrollViewer>
    </Grid>
</Window>

如果您想要更高效/更高效,请参阅这些方便的帖子:

答案 1 :(得分:0)

还有另一种显示图像的方法。在图片上设置max-es,这样它在视觉上的负载不会超过所需的大小。

<Image Source="{Binding Source}"
       Stretch="UniformToFill"
       MaxHeight="200"
       MaxWidth="400"/>

下面的图像显示了按原样加载的两个图像,一个小图像和一个大图像。左侧显示了一个大的爆炸,越过边界。右图显示了大图的适当收缩。

enter image description here

要防止较小的图像过大(如右图所示),请设置StretchDirection="DownOnly",以防止较小的图像扩大。