2
我试图在后台线程(BackgroundWorker)中创建一个BitmapImage,但是我的函数只能立即返回null并且不会进入Deployment.Current.Dispatcher.BeginInvoke。当我在UI线程中使用这个函数时,一切都很好。到文件的路径是正确的(这是一个.JPG图片)创建BitmapImage的背景
public static BitmapImage convertFileToBitmapImage(string filePath)
{
BitmapImage bmp = null;
Uri jpegUri = new Uri(filePath, UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(jpegUri);
Deployment.Current.Dispatcher.BeginInvoke(new Action( () =>
{
bmp = new BitmapImage();
bmp.SetSource(sri.Stream);
}));
return bmp;
}
在Windows Phone 7.1中没有Invoke方法,或者你的意思是另一种方法? – igla
@igla啊错过了你的Windows手机标签!但是,问题仍然是你的回归太快。 – James
很多帮助!好的解决方案 – igla