"mai“是包含图像、文本和小图像的网格名称。我在博客上写了一篇文章,内容是通过WriteableBitmap (用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());
}当我在模拟器上以调试模式运行这个程序时,我会收到一条意外错误消息。我还将这个应用程序部署到我的手机上(并将其与计算机断开连接),并收到了同样的错误。
基本上,我试着保存一个从相机辊上选择的剪裁图像,上面覆盖了一些文本。它喜欢将这个“新”图像保存到相机滚筒中。
更新:
我也是这样做的,结果是一样的:
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)发布于 2012-03-09 15:31:05
问题是流被定位为字节数据。因此,在将您的流传递到媒体库之前,您必须从开始时开始寻找它。这会解决你的问题。下面是一个示例:(顺便说一句,对每个IDisposable对象使用using结构是一个很好的实践)
using (MemoryStream stream = new MemoryStream())
{
WriteableBitmap bitmap = new WriteableBitmap(LayoutRoot, null);
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
using (MediaLibrary mediaLibrary = new MediaLibrary())
mediaLibrary.SavePicture("Picture.jpg", stream);
}
MessageBox.Show("Picture Saved...");发布于 2012-04-22 08:25:32
在经历了很多次的失败之后,我发现我的问题是缺少了WMAppManifest.xml的功能
<Capability Name="ID_CAP_MEDIALIB" />错误信息是如此模糊,以至于我不得不浪费大量的时间来解决这个问题。
https://stackoverflow.com/questions/9634970
复制相似问题