Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:24:47+00:00 2026-05-22T14:24:47+00:00

I’m making a drawing program in C# for Windows Phone. This is for Windows

  • 0

I’m making a drawing program in C# for Windows Phone.

This is for Windows Phone, so a bunch of stuff doesn’t work that would work in C#.

At the start of opening a .XAML page, I have a blank Canvas. The user draws on the Canvas, then clicks Save. When he/she clicks Save, I want the program to be able to save the image on the Canvas.

I have the following code so far:

        IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
        StreamReader sr = null;

        sr = new StreamReader(new IsolatedStorageFileStream("Data\\imagenum.txt", FileMode.Open, isf));
        test = sr.ReadLine();
        sr.Close();

        int.TryParse(test, out test2);

        test2 = test2 + 1;

        IsolatedStorageFile isf2 = IsolatedStorageFile.GetUserStoreForApplication();
        isf2.CreateDirectory("Data");
        StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Data\\imagenum.txt", FileMode.Create, isf2));
        sw.WriteLine(test2);
        //This writes the content of textBox1 to the StreamWriter. The StreamWriter writes the text to the file.
        sw.Close();

This code finds what an appropriate name for the image would be.

I’ve also found various other code snippets on the web:

            // Construct a bitmap from the button image resource.
        test = "Images/" + test + ".jpg";
        using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            WriteableBitmap bmImage = new WriteableBitmap(image);
            if (!store.DirectoryExists("Images"))
            {
                store.CreateDirectory("Images");
            }
            using (IsolatedStorageFileStream isoStream =
            store.OpenFile(@"Images\" + test + ".jpg", FileMode.OpenOrCreate))
            {
                Extensions.SaveJpeg(
                bmImage,
                isoStream,
                bmImage.PixelWidth,
                bmImage.PixelHeight,
                0,
                100);
            }
        }

The above is an ugly mess of code from tutorials on MSDN and my own badly scraped together code.

(It doesn’t work, for semi-obvious reasons)

How would I save the canvas to IsolatedStorage, as an image?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:24:47+00:00Added an answer on May 22, 2026 at 2:24 pm

    Your first section where you appear to be writing the last used number to a text file in IsolatedStorage seems like a lot of work to do something relatively simple. You can replace that whole section with this:

    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    int imageNumber = 0;
    settings.TryGetValue<int>("PreviousImageNumber", out imageNumber);
    imageNumber++;
    

    You can save the image to IsolatedStorage like this:

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (!isf.DirectoryExists("Images"))
        {
            isf.CreateDirectory("Images");
        }
        IsolatedStorageFileStream fstream = isf.CreateFile(string.Format("Images\\{0}.jpg",imageNumber));
    
        WriteableBitmap wbmp = new WriteableBitmap(image);
        Extensions.SaveJpeg(wbmp, fstream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
        fstream.Close();
    }
    

    But it would probably make more sense to save the image to their MediaLibrary like this:

    MediaLibrary library = new MediaLibrary();
    WriteableBitmap wbmp = new WriteableBitmap(image);
    
    MemoryStream ms = new MemoryStream();
    Extensions.SaveJpeg(wbmp, ms, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
    ms.Seek(0, SeekOrigin.Begin);
    library.SavePicture(string.Format("Images\\{0}.jpg",imageNumber), ms);
    

    Either way, you can then save the imageNumber back to the IsolatedStorageSettings like this:

    settings["PreviousImageNumber"] = imageNumber;
    settings.Save();
    

    I had assumed the image used above was set somewhere else in your code. I haven’t saved a Canvas to an image before, but some quick searching turned up this blog where an example is given using the WriteableBitmap which indicates you can just replace the image variable with your canvas element:

    WriteableBitmap wbmp = new WriteableBitmap(yourCanvas, null);
    

    The article also indicates that the Canvas’ background will be ignored and replaced with a black image but that you can overcome this by first adding a rectangle to the Canvas with whatever background you want. Again, I haven’t tried this. If this doesn’t work you should consider posting another question specifically related to transforming a Canvas to an Image since this is really a separate issue from your original question about saving images.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.