【发布时间】:2015-10-19 02:23:53
【问题描述】:
我正在尝试使用电影封面创建 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);
}
}
如果有人能够解决这个问题,我将非常感激:(非常感谢!
【问题讨论】:
-
您是否尝试将 141 号的图像文件换成另一个?
-
可能是因为一些图片链接坏了或者链接上没有更多图片了?那我该如何解决这个问题? :/ 我如何定义 - 在 http://...com/img.jpg 上是否有图像?对不起我的英语不好:(
-
您可以点击错误窗口中的“查看详细信息”吗?深入Inner Exceptions,这应该会发现问题。
-
解码图像时发生异常。您是否检查了构建的 URL 以确保您确实获得了您期望的图像?
-
链接以 .jpg 结尾,但我认为有时链接可能是这样的:filmoo.ro/wp-content/uploads/2014/10/Addicted-2014.jpg