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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:03:24+00:00 2026-06-11T02:03:24+00:00

I am using WPF to generate tile images for my WinRT app. I have

  • 0

I am using WPF to generate tile images for my WinRT app. I have a tile UserControl which is converted to PNG and this works well (It does, please don’t tell me otherwise). WinRT passes me a scale property 100% (320×150), 140% (434×210) and 180% (558×270) which I use to generate the correct size of image.

For when I want to use images in my tile. I have replicated the image selection functionality of WinRT (You can supply thee scales of images and WinRT apps automatically select the correct scale) in my tile UserControl’s code behind. So depending on the scale I select a bigger or smaller image source. However, on the larger scales my font size remains the same size and looks really small. I don’t think I need to change the font size based on the scale as this is not what happens in WinRT, so it must be the code I’m using to convert my UserControl to a PNG and something to do with DPI. Here is my conversion Code:

// I pass in 320x150 or 434x210 or 558x270 depending on the scale.
public static MemoryStream ToPng(
    this FrameworkElement frameworkElement, 
    double width, 
    double height)
{
    BitmapSource bitmapSource = ToBitmapSource(frameworkElement, width, height);

    PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
    pngBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapSource));

    MemoryStream memoryStream = new MemoryStream();
    pngBitmapEncoder.Save(memoryStream);

    memoryStream.Position = 0;

    return memoryStream;
}

public static BitmapSource ToBitmapSource(
    this FrameworkElement frameworkElement, 
    double width, 
    double height)
{
    Size renderingSize = new Size(width, height);
    frameworkElement.Measure(renderingSize);
    Rect renderingRectangle = new Rect(new Point(0, 0), renderingSize);
    frameworkElement.Arrange(renderingRectangle);
    frameworkElement.UpdateLayout();

    Rect bounds = VisualTreeHelper.GetDescendantBounds(frameworkElement);
    RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
        (int)frameworkElement.ActualWidth,
        (int)frameworkElement.ActualHeight,
        96,
        96,
        PixelFormats.Pbgra32);

    DrawingVisual drawingVisual = new DrawingVisual();

    using (DrawingContext drawingContext = drawingVisual.RenderOpen())
    {
        VisualBrush visualBrush = new VisualBrush(frameworkElement);
        drawingContext.DrawRectangle(visualBrush, null, new Rect(new Point(), bounds.Size));
    }

    renderBitmap.Render(drawingVisual);

    return renderBitmap;
}

Thanks for any help. Much appreciated.

  • 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-11T02:03:26+00:00Added an answer on June 11, 2026 at 2:03 am

    I needed to change the above code so that I measure and arrange the frameworkElement as 310×150. I then render it to the final scale size e.g. 558×270 and set the DPI to (96/100)*scale where the scale is 180 in this case.

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

Sidebar

Related Questions

I am using WPF UserControl and I have a grid so I want to
I have a requirement to generate a report in WPF which is simply a
We are using XamDataGrid in our WPF application. It works well, we added support
I have been using WPF for a few years now and don't have any
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as
Im using Crytal report WPF Application to generate a report with xml file and
I'm coding a GUI using WPF and Expression Blend for an application which is
I'm trying to generate a PNG file using C#. Everything I google seems to
So I am using C# with WPF. I have a list box where I
I have a .net wpf app that I am deploying, including the .net4 client

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.