私はWPFでプログラムを開発しており、Webから画像を取得し、画像コントロールを使用しています。私の画像リストには50枚の写真があります(vimeoのサムネイルから)。すべてが正常に見えますが、番号は45です。画像に問題があり、45番目の画像に到達すると、次の例外が発生します。
値が期待範囲内にありません。
例外http://img232.imageshack.us/img232/2748/5688301315b2497090468bc.png
try-catchを使用しましたが、キャッチできません。Bitmapクラスで発生するためです。詳細は次のとおりです。
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.OnDownloadCompleted(オブジェクト送信者、EventArgs e)で System.Windows.Media.UniqueEventHelper.InvokeEvents(オブジェクト送信者、EventArgs args)で System.Windows.Media.Imaging.LateBoundBitmapDecoder.DownloadCallback(Object arg)で System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback、Object args、Int32 numArgs)で MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(オブジェクトソース、デリゲートメソッド、オブジェクト引数、Int32 numArgs、デリゲートcatchHandler)で System.Windows.Threading.DispatcherOperation.InvokeImpl()で System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)で System.Threading.ExecutionContext.RunInternal(ExecutionContext executeContext、ContextCallbackコールバック、オブジェクト状態、ブール値preserveSyncCtx)で System.Threading.ExecutionContext.Run(ExecutionContext executeContext、ContextCallbackコールバック、オブジェクト状態、ブール値preserveSyncCtx)で System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext、ContextCallbackコールバック、オブジェクト状態)で System.Windows.Threading.DispatcherOperation.Invoke()で System.Windows.Threading.Dispatcher.ProcessQueue()で System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&handled)で MS.Win32.HwndWrapper.WndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&handled)で MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)で System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback、Object args、Int32 numArgs)で MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(オブジェクトソース、デリゲートメソッド、オブジェクト引数、Int32 numArgs、デリゲートcatchHandler)で System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority、TimeSpan timeout、Delegate method、Object args、Int32 numArgs)で MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam)で MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&msg)で System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrameフレーム)で System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrameフレーム)で System.Windows.Threading.Dispatcher.Run()で System.Windows.Application.RunDispatcher(オブジェクト無視)で System.Windows.Application.RunInternal(ウィンドウウィンドウ)で System.Windows.Application.Run(ウィンドウウィンドウ)で System.Windows.Application.Run()で C:\ ......... \ obj \ x86 \ Debug \ App.g.cs:line 0のyoutube.App.Main()で System.AppDomain._nExecuteAssembly(RuntimeAssemblyアセンブリ、String [] args)で System.AppDomain.ExecuteAssembly(String assemblyFile、Evidence assemblySecurity、String [] args)で Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()で System.Threading.ThreadHelper.ThreadStart_Context(オブジェクト状態)で System.Threading.ExecutionContext.RunInternal(ExecutionContext executeContext、ContextCallbackコールバック、オブジェクト状態、ブール値preserveSyncCtx)で System.Threading.ExecutionContext.Run(ExecutionContext executeContext、ContextCallbackコールバック、オブジェクト状態、ブール値preserveSyncCtx)で System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext、ContextCallbackコールバック、オブジェクト状態)で System.Threading.ThreadHelper.ThreadStart()で
これが私のコードです:
for (int i = 0; i <50 ; i++)
{
product p = new product();
Common.SelectedOldColor = p.Background;
p.VideoInfo = results[i];
Common.Products.Add(p, false);
p.Visibility = System.Windows.Visibility.Hidden;
p.Drop_Event += new product.DragDropEvent(p_Drop_Event);
main.Children.Add(p);
}
プロパティを設定すると、次のp.VideoInfo = results[i];
ように割り当てられます。
private VideoList videoInfo;
public VideoList VideoInfo
{
get { return videoInfo; }
set
{
videoInfo = value;
label1.Content = videoInfo.Title;
try
{
image1.Source = new BitmapImage(new Uri(videoInfo.ThumbNail));
}
catch (Exception ex)
{
}
}
}
image1.Source = new BitmapImage(new Uri(videoInfo.ThumbNail));
これが問題の原因です。しかし、この画像のためだけに:
何度も試してみましたが、それぞれの画像は問題ありません。しかし、これは違いますか?多分それはぼやけていますか?
この問題を解決するにはどうすればよいですか?たぶん私は別の方法を使ってソースをimage1に割り当てることができますか?
よく説明したと思います。