首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ArgumentException in PresentationCore.dll

ArgumentException in PresentationCore.dll
EN

Stack Overflow用户
提问于 2015-07-28 13:32:50
回答 2查看 1.3K关注 0票数 0

我正在尝试用电影封面来创建WrapPanel。当我加载140个覆盖时,一切都正常,但是当我加载141个覆盖时,

代码语言:javascript
复制
    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: 

我的代码看起来像那个

代码语言:javascript
复制
<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);
   }
}

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-28 16:59:45

代码语言:javascript
复制
i.CreateOptions |= BitmapCreateOptions.IgnoreColorProfile;

多亏了Rafael Rivera

票数 0
EN

Stack Overflow用户

发布于 2015-07-28 15:05:51

*:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31677848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档