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 8739535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:57:23+00:00 2026-06-13T10:57:23+00:00

I’m developping a silly application that: – opens a pictures from media library, –

  • 0

I’m developping a silly application that:
– opens a pictures from media library,
– puts the chosen image in a grid element (which contains a TextBlok element)
– save the pictures in the “saved pictures” album.

My XAML code is:

<controls:PanoramaItem Header="Image Selection" Height="652">
<Grid Name="markedImage" Margin="0,0,4,89">
    <Image x:Name="img" Stretch="Fill" Margin="0,0,0,10"></Image>
    <TextBlock x:Name="text" Text="Hello!">
        <i:Interaction.Behaviors>
            <el:MouseDragElementBehavior ConstrainToParentBounds="True"/>
        </i:Interaction.Behaviors>
    </TextBlock>
</Grid>

and the code to open and save the chosen picture is:

private void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        try
        {
            BitmapImage image = new BitmapImage();
            image.SetSource(e.ChosenPhoto);
            WriteableBitmap wbp = new WriteableBitmap(image);
            this.img.Source = image;
            height = image.PixelHeight;
            width = image.PixelWidth;
            MessageBox.Show("H: " + height + "\t" + "W: " + width);
        }
        catch 
        { 
            MessageBox.Show("Disconnect your device from Zune"); 
        }
    }
private void save_Click(object sender, System.EventArgs e)
    {

        WriteableBitmap marked = new WriteableBitmap(this.markedImage, null);
        ThreadPool.QueueUserWorkItem(callback =>
        {
            MemoryStream ms = new MemoryStream();
            marked.SaveJpeg(ms, (width * 2), (height * 2), 0, 100);
            using (MediaLibrary lib = new MediaLibrary())
                lib.SavePicture("Test", ms.ToArray());
        });
        MessageBox.Show("H: " + marked.PixelHeight + "\t" + "W: " + marked.PixelWidth);

        // wbm.SaveToMediaLibrary("SavedPicture.jpg", true);

        MessageBox.Show("Picture saved successfully");
    }

I can’t post pictures because I’m a new user, anyway pictures (orignal and saved pic) have the same height and width but they look different
I think that the problem is the grid dimension and Stretch property. I tried different combo but results were not good.
Some suggestion?

edit: i earned reputation point
original pics is
original pics

saved pics is
saved pics

if you open both in another window, you can see the difference

  • 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-06-13T10:57:24+00:00Added an answer on June 13, 2026 at 10:57 am

    The problem is quite simple to understand: basically, you’re doing a ‘screenshot’ of your grid. Therefore, the size of the generated picture is the same as the size of the grid. Hence the down-sampled picture.

    Fixing that however can be tricky. I can suggest two ways:

    1. Recreate programmatically the grid and its contents in the code-behind, then create the WriteableBitmap from this new grid

    2. Remove the grid from its parent control just before executing your image-generation code (then the grid will be able to use as much space as needed), and add it back afterwards:

      <Grid x:Name="ParentGrid" Grid.Row="1" Width="200" Height="150">
          <Grid Name="markedImage" Margin="0,0,4,89">
              <Image x:Name="img" Source="Images/Test.jpg" Stretch="Fill" Margin="0,0,0,10"></Image>
              <TextBlock x:Name="text" Text="Hello!">
                  <i:Interaction.Behaviors>
                      <el:MouseDragElementBehavior ConstrainToParentBounds="True"/>
                  </i:Interaction.Behaviors>
              </TextBlock>
          </Grid>
      </Grid>
      

      And the code-behind:

      this.ParentGrid.Children.Remove(this.markedImage);
      
      WriteableBitmap marked = new WriteableBitmap(this.markedImage, null);          
      
      MemoryStream ms = new MemoryStream();
      marked.SaveJpeg(ms, 1349, 1437, 0, 100);
      using (MediaLibrary lib = new MediaLibrary())
          lib.SavePicture("Test", ms.ToArray());
      
      MessageBox.Show("H: " + marked.PixelHeight + "\t" + "W: " + marked.PixelWidth);
      
      MessageBox.Show("Picture saved successfully");
      
      this.ParentGrid.Children.Add(this.markedImage);
      
    • 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
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 have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have a text area in my form which accepts all possible characters from

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.