【问题标题】:Image Renders in Win8/Win10 but not Win7图像在 Win8/Win10 中渲染,但不在 Win7 中
【发布时间】:2016-12-19 21:39:10
【问题描述】:

我的文档中有以下 XAML:

<Border HorizontalAlignment="Right" VerticalAlignment="Bottom"
        Height="100" Width="100"
        BorderBrush="Red" BorderThickness="2">
    <Image x:Name="image"
           Source="http://myinternalserver/mywebservice/getimage.aspx?id=1234&amp;ContentType=Image" />
</Border>

图像在 Win10 和 Win8 中显示良好,但在 Win7 中,我得到的只是一个带有透明背景的红色边框,里面没有图像。当我使用静态 URL 时,例如 google 徽标,它会呈现在所有版本中。

有人知道如何在 Windows 7 中渲染图像吗?

【问题讨论】:

  • 图片类型是什么? Windows 7 是否原生支持该类型?
  • 是的,它是 PNG,有时是 JPG。没有什么异国情调。
  • 您可以从浏览器访问该链接吗?在我看来,它不像 xaml/c# 问题。更像是 Windows 设置问题...
  • 是的,它在两个系统上都可以在浏览器中打开。
  • 可能是服务器问题、标头等。没有复制样本,很难判断。

标签: c# wpf xaml windows-7


【解决方案1】:

根据this postWebUrl 不能指定为BitmapImage 的Source。我建议您创建一个辅助类,而不是在视图的代码隐藏中这样做。我也会冻结创建的图像以提高性能。

【讨论】:

    【解决方案2】:

    尝试通过订阅代码隐藏文件中的Image.ImageFailed 事件来检查可能的异常:

    public MainWindow()
    {
        InitializeComponent();
        image.ImageFailed += ImageFailed;
    }
    
    private void ImageFailed(object sender, ExceptionRoutedEventArgs e)
    {
        Console.WriteLine(e.ErrorException);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多