storing resource image to isolatedstorage throwing System.NullReferenceException

155 Views Asked by At

i am trying to save an image i.e., present in my project to the isolated storage. i tried using the following code but it is throwing System.NullReferenceException.

IsolatedStorageFileStream fileStream1 = myIsolatedStorage.CreateFile("shared/shellcontent/image.jpg");
Uri uri = new Uri(@"/myapp;/component/contact.bmp", UriKind.Relative);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.UriSource = uri;
                    WriteableBitmap wb = new WriteableBitmap(bitmapImage); //throwing exception
                    Extensions.SaveJpeg(wb, fileStream1, wb.PixelWidth, wb.PixelHeight, 0, 85);

i tried with jpg image also. copy to output directory set to copy if never. also tried with build action set to content

............. just tried this code and the exception isn't showing now but still when am setting it to a tile background. its blank

Uri uri = new Uri("contact.jpg", UriKind.Relative);
                    StreamResourceInfo sri = null;
                    sri = Application.GetResourceStream(uri);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(sri.Stream);
                    WriteableBitmap wb = new WriteableBitmap(bitmapImage);
                    Extensions.SaveJpeg(wb, fileStream1, wb.PixelWidth, wb.PixelHeight, 0, 85);

update: issue is resolved. filestream was not closed. silly me

0

There are 0 best solutions below