gpt4 book ai didi

windows-phone-7 - 保存可写位图

转载 作者:行者123 更新时间:2023-12-04 07:28:23 25 4
gpt4 key购买 nike

“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());
}

当我在模拟器上以 Debug模式运行它时,我收到了一条意外错误 消息。我还将此应用程序部署到我的手机(并断开了它与计算机的连接)并收到了同样的错误。

基本上,我正在尝试保存从相机胶卷中选取的裁剪图像,并在其上叠加一些文本。它喜欢将这个"new"图像保存到相机胶卷中。

更新:

我也做了同样的结果:

        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)

最佳答案

问题在于流是定位字节数据。因此,在您将流传输到媒体库之前,您必须将其找回开头。那会解决你的问题。这是一个示例:(顺便说一句,对每个 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...");

关于windows-phone-7 - 保存可写位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9634970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com