Silverlight 将图像保存到IsolatedStorage
以下是将图像保存到独立存储的正确方法吗?
public void imageToStore(Image imageIn)
{
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream s = new IsolatedStorageFileStream(imageIn.Name, FileMode.Create, iso);
using (StreamWriter writer = new StreamWriter(s))
{
writer.Write(imageIn);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:谢谢,安东尼:我完全错过了“Silverlight”部分,下面的链接适用于 System.Drawing 类。相反,您需要详细描述 此处,您可能会立即采用。
原始答案(仅供参考,不适用于您的用例):
查看 Streamwriter 方法 并告诉我您希望使用哪种方法来处理您提供的图像。您会注意到这种类型没有重载,因此 - 它会退回到采用对象的重载。它不知道如何保存任意对象,而只是保存 .ToString() 为此实例返回的任何内容。从上面的链接:
幸运的是,Image 类有一个方法 知道如何将自身保存到一条溪流。用那个。
Edit: Thanks, Anthony: I completely missed the "Silverlight" part, the links below are for the System.Drawing classes. What you need is instead described in detail here and can probably be adopted by you right away.
Original answer (just for reference, not applicable for your use case):
Look at the Streamwriter Methods and tell me which method you'd expect to handle the Image you provide. You'll notice that there's no overload for this type, so - it falls back to the overload that takes an object. That doesn't know how to save an arbitrary object and just saves whatever .ToString() returns for this instance. From the link above:
Fortunately the Image class has a method that knows how to save itself to a stream. Use that.