开发者

Silverlight Save image to IsolatedStorage

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜