基本上,我导航到此页面并将名称作为参数传递给它,然后我使用它从隔离存储中检索该图片。同时我从资产文件夹中检索“框架”。
当我编译代码时,没有发生错误,但是一旦我在运行时到达这部分,我就会得到 frametest 的 nullexception。我之前尝试过构建,frameImage !=null
以确保仍然有一个值出现错误。两个图像都正确加载到 BitMapImage 中,我也可以显示它们(测试过)
BitmapImage image = new BitmapImage();
BitmapImage frameImage = new BitmapImage();
parameter = string.Empty;
if (NavigationContext.QueryString.TryGetValue("parameter", out parameter))
{
picName = parameter + ".jpg";
//call function to load image source from isolateStorage
using (isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore != null)
{
using (isoStream = new IsolatedStorageFileStream(parameter, FileMode.OpenOrCreate, isoStore))
{
if (isoStream != null)
{
image.SetSource(isoStream);
}
}
//close the stream object
isoStream.Close();
}
}
//close the storage object
isoStore.Dispose();
string path = "/Assets/AppGraphics/UserInterface/frame.png";
Uri uriR = new Uri(path, UriKind.Relative);
frameImage = new BitmapImage(uriR);
//error occurs here
WriteableBitmap frameTest = new WriteableBitmap(frameImage);
WriteableBitmap imageTest = new WriteableBitmap(image);
var photo = imageTest;
var frame = frameTest;
var merge = new WriteableBitmap(656, 410);
merge.Blit(new Rect(0, 0, 656, 410), photo, new Rect(0, 0, photo.PixelWidth, photo.PixelHeight)); //draw the photo first
merge.Blit(new Rect(0, 0, 656, 410), frame, new Rect(0, 0, frame.PixelWidth, frame.PixelHeight)); //draw the frame
imgCC.Source = merge;
当对象显然不为空时,我不明白为什么我得到一个空异常。任何帮助或想法表示赞赏。
堆栈跟踪:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.WriteableBitmap_CreateFromSource(WriteableBitmap wb, IntPtr ptrMemory, BitmapSource source, Boolean& bHasProtectedContent)
at System.Windows.Media.Imaging.WriteableBitmap..ctor(BitmapSource source)
at PinAppWindowsPhone.confirmPicture.OnNavigatedTo(NavigationEventArgs e)
at Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs e)
at Microsoft.Phone.Controls.PhoneApplicationPage.Microsoft.Phone.Controls.IPhoneApplicationPage.InternalOnNavigatedToX(NavigationEventArgs e)
at System.Windows.Navigation.NavigationService.RaiseNavigated(Object content, Uri uri, NavigationMode mode, Boolean isNavigationInitiator, IPhoneApplicationPage existingContentPage, IPhoneApplicationPage newContentPage)
at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content, NavigationMode mode)
at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)