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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:11:51+00:00 2026-05-31T15:11:51+00:00

I have some problems with performance in my code… I need to render many-colored

  • 0

I have some problems with performance in my code…
I need to render many-colored rectangles to my DrawingVisual.

The first version is simple:

using (DrawingContext dc = Canvas.RenderOpen())
{
   for (Int32 x = 0; x < widthCount; x++)
      for (Int32 y = 0; y < heightCount; y++)
      {
          Color c;
          Double value = mass[x, y];
          c = GetColorByValue(value);
          dc.DrawRectangle(new SolidColorBrush(c), null,
          new Rect(x * step - step / 2, y * step - step / 2, step, step));
       }
}

And it works normal in case of the quantity of rectangles is about 250×250 (and it gets 200Mb RAM). But if the number of them is 750×750 the process of rendering is too long and slow (gets more than 2.5Gb RAM)

The next step was using a bitmap like a buffer. But there is a problem with the size of my DrawingVisual. Visual is really large.
So it is impossible to create a full-size bitmap because the constructor of RenderTargetBitmap throws the Exception “The image data generated an overflow during processing”.

Finally I created a small bitmap and stretched it to my visual. However the problem is the same (it works too slow and gets a lot of RAM).

What should I do to make the process of rendering elements to get adequate time and sources?

Regards!

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-05-31T15:11:52+00:00Added an answer on May 31, 2026 at 3:11 pm

    Yep! I have found the way to solve this problem!
    For the first time I used the bitmap as a buffer wrongly.
    But now I use it correctly.
    My code:

    //temp visual
    DrawingVisual tmpVisual = new DrawingVisual();
    using (DrawingContext dc = tmpVisual.RenderOpen())
    {
         for (Int32 x = 0; x < widthCount; x++)
              for (Int32 y = 0; y < heightCount; y++)
              {
                  Color c;
                  Double value = mass[x, y];
                  c = GetColorByValue(value);
                  dc.DrawRectangle(new SolidColorBrush(c), null,
                      new Rect(x * step - step / 2, y * step - step / 2, step, step));
              }
    }
    
    //resize visual
    tmpVisual.Transform = new ScaleTransform(maxWidth/(widthCount * step),
                            maxHeight/(heightCount * step));
    
    //visual to bitmap
    RenderTargetBitmap bitmap = 
        new RenderTargetBitmap(maxWidth, maxHeight, 96, 96, PixelFormats.Pbgra32);
    bitmap.Render(tmpVisual);
    
    using (DrawingContext dc = Canvas.RenderOpen())
    {
        Rect rect = new Rect(0, 0, widthCount * step, heightCount * step);
        dc.DrawImage(bitmap, rect);
    }
    

    I have created a temp visual, reduce it and rendered it to the bitmap. Finally I stretched it to my visual.

    I thanks to this topic: Scaling WPF content before rendering to bitmap

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

Sidebar

Related Questions

We have some performance problems with one of our applications. I thought about using
I have some problems sending mails through SMTP using Spring's MailSender interface and the
I have some problems to start programming using cocos2D on linux + android. I
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I
I have some problems on a site with the concurrent access to a list.
I have some problems with OpenCV s cvCanny(...) and the Image data types it
i have some problems with rowspan: var doc1 = new Document(); doc1.SetPageSize(PageSize.A4.Rotate()); string path
I have some problems sending an id though jquery. I have a form select
I have some problems with mod_rewrited at .httacess. We have created a website, the
I have some problems with controlling a while loop inside an event structure. Say

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.