Silverlight 将图像保存到IsolatedStorage

发布于 2024-08-20 04:40:08 字数 427 浏览 7 评论 0 原文

以下是将图像保存到独立存储的正确方法吗?

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

Is the following the correct way to save an image to isolated storage?

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2024-08-27 04:40:08

编辑:谢谢,安东尼:我完全错过了“Silverlight”部分,下面的链接适用于 System.Drawing 类。相反,您需要详细描述 此处,您可能会立即采用。


原始答案(仅供参考,不适用于您的用例):

查看 Streamwriter 方法 并告诉我您希望使用哪种方法来处理您提供的图像。您会注意到这种类型没有重载,因此 - 它会退回到采用对象的重载。它不知道如何保存任意对象,而只是保存 .ToString() 为此实例返回的任何内容。从上面的链接:

写入一个文本表示
通过调用来对象文本流
该对象上的 ToString。 (遗传
来自 TextWriter。)

幸运的是,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:

Writes the text representation of an
object to the text stream by calling
ToString on that object. (Inherited
from TextWriter.)

Fortunately the Image class has a method that knows how to save itself to a stream. Use that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文