代码之家  ›  专栏  ›  技术社区  ›  b00sted 'snail'

PresentationCore.dll中的ArgumentException

  •  0
  • b00sted 'snail'  · 技术社区  · 9 年前

    我正在尝试用电影封面制作WrapPanel。当我加载140覆盖时,一切都正常,但当我加载141覆盖时 :

        System.ArgumentException was unhandled
      HResult=-2147024809
      Message=Value does not fall within the expected range.
      Source=PresentationCore
      StackTrace:
           at System.Windows.Media.ColorContext.GetColorContextsHelper(GetColorContextsDelegate getColorContexts)
           at System.Windows.Media.Imaging.BitmapFrameDecode.get_ColorContexts()
           at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
           at System.Windows.Media.Imaging.BitmapImage.OnDownloadCompleted(Object sender, EventArgs e)
           at System.Windows.Media.UniqueEventHelper.InvokeEvents(Object sender, EventArgs args)
           at System.Windows.Media.Imaging.LateBoundBitmapDecoder.DownloadCallback(Object arg)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.ProcessQueue()
           at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run()
           at pCore.App.Main() in c:\Users\narkoze\Desktop\vanagz\pCore\pCore\obj\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.ArgumentException
           HResult=-2147024809
           Message=Value does not fall within the expected range.
           InnerException: 
    

    我的代码看起来像这样 :

    <ScrollViewer>
     <WrapPanel Name="MyWrapPanel" x:FieldModifier="public" />
    </ScrollViewer>
    
    using (var client = new WebClient())
    {
       var content = client.DownloadString("http://www.");
       var movies = JsonConvert.DeserializeObject<List<MovieAttributes>>(content);
       foreach (var movie in movies)
       {
          TextBox tb = new TextBox();
          tb.Text = movie.Name;
    
          Image img = new Image();
          BitmapImage bi = new BitmapImage();
          Uri cover = new Uri(movie.Cover, UriKind.RelativeOrAbsolute);
          bi.UriSource = cover;
          img.Source = bi;
    
          StackPanel sp = new StackPanel();
          sp.Children.Add(tb);
          sp.Children.Add(img);
    
          MyWrapPanel.Children.Add(sp);
       }
    }
    

    如果有人能解决这个问题,我将非常感激:(非常感谢!

    2 回复  |  直到 9 年前
        1
  •  0
  •   b00sted 'snail'    9 年前

    内部例外:::: enter image description here

        2
  •  0
  •   Community CDub    7 年前
    i.CreateOptions |= BitmapCreateOptions.IgnoreColorProfile;
    

    幸亏 Rafael Rivera