「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