【问题标题】:Error HRESULT 0x88982F72 when trying streaming image file尝试流式传输图像文件时出现错误 HRESULT 0x88982F72
【发布时间】:2012-07-04 19:21:41
【问题描述】:

我正在尝试使用下面的简单代码流式传输图像文件。

Stream stream = File.OpenRead(myFileInfo.ToString());

当我这样做时,Visual Studio 会向我发送一个异常。 这个文件是一个简单的 jpeg。 在调试模式下,我通过 BitmapDecoder 类看到我的文件没有帧。与其他相同扩展名的文件相比,都只有一个Frame。

我已经尝试了使用 FileStream 类的解决方案,但它不起作用:'(

我的主要代码是这样的:

BitmapImage myBitmapImage = new BitmapImage();
using (Stream stream = File.OpenRead(fileInfo.ToString()))
{
    myBitmapImage.BeginInit();
    myBitmapImage.StreamSource = stream;
    myBitmapImage.EndInit();
}

它是在转换器中编写的,自然绑定到 Image 控件。 但是在下一行的 Image.Source 属性中设置之前抛出异常:

myBitmapImage.EndInit();

另一个细节:图像文件可以用 Photoshop、Paint.net 和其他程序打开。当这些最后保存副本时,使用相同的代码打开新文件不会出现问题。

但我不能告诉我们的客户一直这样做(一天大约 50 次:s)。

谢谢。

我的详细信息如下:

System.IO.IOException was unhandled by user code
  HResult=-2146232800
  Message=Impossible de lire à partir du flux.
  Source=PresentationCore
  StackTrace:
       à System.Windows.Media.ColorContext.GetColorContextsHelper(GetColorContextsDelegate getColorContexts)
       à System.Windows.Media.Imaging.BitmapFrameDecode.get_ColorContexts()
       à System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
       à System.Windows.Media.Imaging.BitmapImage.EndInit()
       à EDIs.Imaging.Converter.UriToBitmapSourceConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) dans C:\Users\Gaet\Documents\Visual Studio 2010\Projects\DotNet\MDP.EDIs\EDIs.Imaging\Converter\UriToBitmapSourceConverter.cs:ligne 40
       à System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
       à System.Windows.Data.BindingExpression.Activate(Object item)
       à System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
       à System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
       à System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
       à System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
       à System.Windows.FrameworkTemplate.ReceivePropertySet(Object targetObject, XamlMember member, Object value, DependencyObject templatedParent)
       à System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__4(Object sender, XamlSetValueEventArgs setArgs)
       à System.Xaml.XamlObjectWriter.OnSetValue(Object eventSender, XamlMember member, Object value)
       à System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
       à System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
       à System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
       à System.Xaml.XamlObjectWriter.WriteEndObject()
       à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       à System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
  InnerException: System.Runtime.InteropServices.COMException
       HResult=-2003292302
       Message=Exception de HRESULT : 0x88982F72
       ErrorCode=-2003292302
       InnerException: 

【问题讨论】:

    标签: c# wpf stream hresult


    【解决方案1】:

    看看 Scott Hanselman Dealing with Images with Bad Metadata - Corrupted Color Profiles in WPF 的这篇博文

    他建议的修复在我的情况下有效。来自博客:

    var bi = new BitmapImage();
    bi.BeginInit();
        bi.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
        bi.UriSource = new Uri("http://hanselman.com/blog/images/JPGwithBadColorProfile.jpg");
    bi.EndInit();
    
    foo.Source = bi;
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:
          BitmapImage Art3 = new BitmapImage();
          using (FileStream stream = File.OpenRead("c:\\temp\\Album.jpg"))
          {
              Art3.BeginInit();
              Art3.StreamSource = stream;
              Art3.EndInit();
          }
          artwork.Source = Art3;
      

      “艺术品”是应该显示图像的 XAML 对象。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-31
        • 2017-02-11
        • 2016-02-17
        • 1970-01-01
        • 2011-06-02
        • 2019-04-17
        • 2015-10-08
        相关资源
        最近更新 更多