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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:19:42+00:00 2026-06-05T08:19:42+00:00

In a WPF application, what’s the preferable way to do such a thing ?

  • 0

In a WPF application, what’s the preferable way to do such a thing ?
If I have a grid of 1000 x 1000 size, how can I save it as an image with 200 x 200 size for example ??

Thanks!

  • 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-05T08:19:44+00:00Added an answer on June 5, 2026 at 8:19 am

    Modified my answer below a bit so it would work for this scenario
    Slice Large WPF Canvas Into Many Small PNG Images

    Call it like this

    SaveFrameworkElementToPng(myGrid, 200, 200, "MyImage.png");
    

    SaveFrameworkElementToPng

    private void SaveFrameworkElementToPng(FrameworkElement frameworkElement,
                                           int width,
                                           int height,
                                           string filePath)
    {
        BitmapImage bitmapImage = VisualToBitmapImage(frameworkElement);
        SaveImage(bitmapImage, width, height, filePath);
    }
    
    public BitmapImage VisualToBitmapImage(FrameworkElement frameworkElement)
    {
        RenderTargetBitmap rtb = new RenderTargetBitmap((int)frameworkElement.ActualWidth,
                                                        (int)frameworkElement.ActualHeight,
                                                        96d,
                                                        96d,
                                                        PixelFormats.Default);
        rtb.Render(frameworkElement);
    
        MemoryStream stream = new MemoryStream();
        PngBitmapEncoder encoder = new PngBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(rtb));
        encoder.Save(stream);
    
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.BeginInit();
        bitmapImage.StreamSource = stream;
        bitmapImage.EndInit();
    
        return bitmapImage;
    }
    
    public void SaveImage(BitmapImage sourceImage,
                            int width,
                            int height,
                            string filePath)
    {
        TransformGroup transformGroup = new TransformGroup();
        ScaleTransform scaleTransform = new ScaleTransform();
        scaleTransform.ScaleX = (double)width / sourceImage.PixelWidth;
        scaleTransform.ScaleY = (double)height / sourceImage.PixelHeight;
        transformGroup.Children.Add(scaleTransform);
    
        DrawingVisual vis = new DrawingVisual();
        DrawingContext cont = vis.RenderOpen();
        cont.PushTransform(transformGroup);
        cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight)));
        cont.Close();
    
        RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
        rtb.Render(vis);
    
        PngBitmapEncoder encoder = new PngBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(rtb));
    
        using (FileStream stream = new FileStream(filePath, FileMode.Create))
        {
            encoder.Save(stream);
            stream.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf application that is leaking memory...is there a way to detect
(using WPF application) I get an error when i want to save a bool
I have a WPF application in which i have to do a long running
My WPF application is becoming a real pain. I have created a Window and
I have a WPF application where I'm trying to create a diagnostics panel that's
I have a WPF application (.NET Framework 4) with a custom window-border. I've disabled
I have a WPF application and am using the WPF toolkit autocomplete box in
I have a small WPF application in which I have a list of files.
I have a WPF application that we have integrated credit card processing into. We're
we have a wpf application..in the Home page we have Work,Help,Approve Search tabs.. When

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.