基本上我导航到此页面并将其作为参数传递给我,然后我将其用于从隔离存储中检索该图片。同时我从assets文件夹中检索“frame”。
当我编译代码时没有发生错误,但是一旦我在运行期间到达这个部分,我就得到了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;
我不明白为什么我得到一个nullexception,当对象显然不是null。任何帮助或想法都表示赞赏。
堆栈跟踪:
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)