“mai”是包含图像,文本和小图像的网格名称。我正在关注一篇关于如何通过使其成为WriteableBitmap(使用UIelment)来添加图像的博文。保存WriteableBitmap
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());
}
当我在模拟器上调试模式下运行此我得到一个意外错误消息。我也部署了这个应用程序到我的手机(并从计算机断开连接),并收到相同的错误。
基本上我试图保存从相机卷中挑选的裁剪图像,并在其上覆盖一些文字。它喜欢将这个“新”图像保存到相机胶卷中。
更新:
我也具有相同的结果做:
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();
更新:
错误的堆栈跟踪:
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)
在哪种情况下,你可以称之为? 'wbm.PixelWidth'和wbm.PixelHeight是否有正确的值? – Ku6opr 2012-03-09 13:46:52
我刚刚检查过,宽度值= 456,高度值= 535 - 看起来它抓住了网格的大小:mai – webdad3 2012-03-09 13:51:54
我将代码添加到'Loaded'事件并且所有作品 – Ku6opr 2012-03-09 13:59:07