"mai" is the grid name that contains the image, text and small image. I was following a blog post about being able add to your image by making it a WriteableBitmap (with a UIelment).
try
{
WriteableBitmap wbm = new WriteableBitmap(mai, null);
MediaLibrary ml = new MediaLibrary();
Stream stream = new MemoryStream();
wbm.SaveJpeg(stream, wbm.PixelWidth, wbm.PixelHeight, 0, 100);
ml.SavePicture("mai.jpg", stream);
MessageBox.Show("Picture Saved...");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
When I run this in debug mode on the emulator I get an Unexpected Error message. I've also deployed this app to my phone (and disconnected it from the computer) and received the same error.
Basically I'm trying to save a cropped image picked from the Camera Roll with some text overlayed on top of it. It like to save this "new" image into the Camera Roll.
Update:
I also did this with the same result:
WriteableBitmap wbm2 = new WriteableBitmap(mai, null);
string tempjpeg = "tempmedicalertinfo";
// create a virtual store and file stream. check for duplicate tempjpeg files.
var mystore = IsolatedStorageFile.GetUserStoreForApplication();
if (mystore.FileExists(tempjpeg))
{
mystore.DeleteFile(tempjpeg);
}
IsolatedStorageFileStream myfilestream = mystore.CreateFile(tempjpeg);
wbm2.SaveJpeg(myfilestream, 500, 500, 0, 100);
myfilestream.Close();
// create a new stream from isolated storage, and save the jpeg file to the media library on windows phone.
myfilestream = mystore.OpenFile(tempjpeg, FileMode.Open, FileAccess.Read);
// save the image to the camera roll or saved pictures album.
MediaLibrary library = new MediaLibrary();
// save the image to the saved pictures album.
try
{
Picture pic = library.SavePictureToCameraRoll("mai.jpg", myfilestream);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
myfilestream.Close();
Update:
Stack Trace of the error:
at Microsoft.Xna.Framework.Helpers.ThrowExceptionFromErrorCode(ErrorCodes error)
at Microsoft.Xna.Framework.Media.MediaLibrary.SavePicture(String name, Stream source)
at PB.MASetup.saveImage_Click(Object sender, EventArgs e)
at Microsoft.Phone.Shell.ApplicationBarItemContainer.FireEventHandler(EventHandler handler, Object sender, EventArgs args)
at Microsoft.Phone.Shell.ApplicationBarIconButton.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBarIconButtonContainer.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBar.OnCommand(UInt32 idCommand)
at Microsoft.Phone.Shell.Interop.NativeCallbackInteropWrapper.OnCommand(UInt32 idCommand)