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

  • Home
  • SEARCH
  • 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 3215228
In Process

The Archive Base Latest Questions

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

I want to create some kind of simulation. There will be numerous sprites floating

  • 0

I want to create some kind of simulation. There will be numerous sprites floating around. Because I think that rendering every frame thousand times the same primitives which make up a sprite, will be slow, I want render them once into a bitmap and then show this sprite every frame.

But it doesn’t seem to work, the screen stays white.

My WPF source is trivial:

<Window x:Class="WPFGraphicsTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="800" Width="1000">
    <Canvas>

    </Canvas>
</Window>

And this is my code:

    public partial class MainWindow : Window
    {
        Ellipse e;
        RenderTargetBitmap bmp2;

        public MainWindow()
        {
            InitializeComponent();

            e = new Ellipse();
            e.Width = 40;
            e.Height = 40;
            e.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 200));

            ((Canvas)this.Content).Children.Add(e);
            ((Canvas)this.Content).Measure(new Size(1000, 800));
            ((Canvas)this.Content).Arrange(new Rect(new Size(1000, 800)));

            RenderTargetBitmap bmp2 = new RenderTargetBitmap(40, 40, 96, 96, PixelFormats.Pbgra32);

            bmp2.Render(e);
            ((Canvas)this.Content).Children.Remove(e);
}


        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawImage(bmp2, new Rect(100,100, 40, 40));

        }
}

Why doesn’t this work?

  • 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-17T15:09:12+00:00Added an answer on May 17, 2026 at 3:09 pm

    You could put an Image object on the Canvas and then use the RenderTargetBitmap to update the image. For example

    <Window x:Class="WPFGraphicsTest.MainWindow" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            Title="MainWindow" Height="800" Width="1000"> 
        <Canvas> 
          <Image Name="frameImage" />
        </Canvas> 
    </Window> 
    

    Then you can update the image like this, for the example, I am just rendering a new ellipse every 100 ms. Of course you should manage the Pens and Brushes better than what I show here, this is just an example to clarify the suggestion.

    public partial class MainWindow : Window
      {
        DispatcherTimer _timer = new DispatcherTimer();
    
        RenderTargetBitmap _renderSurface = 
          new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32);
    
        Random _rnd = new Random();
    
        public MainWindow()
        {
          InitializeComponent();
    
          _timer = new DispatcherTimer();
          _timer.Interval = TimeSpan.FromMilliseconds(100);
          _timer.Tick += new EventHandler(_timer_Tick);
          _timer.Start();      
        }
    
        void _timer_Tick(object sender, EventArgs e)
        {
          DrawingVisual visual = new DrawingVisual();
          DrawingContext context = visual.RenderOpen();
          int value = _rnd.Next(40);
          context.DrawEllipse(
            new SolidColorBrush(Colors.Red), 
            new Pen(new SolidColorBrush(Colors.Black), 1), 
            new Point(value, value), value, value);
          context.Close();
    
          _renderSurface.Render(visual);
          frameImage.Source = _renderSurface;
        }    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some kind of test data and want to create a unit test
I want to create a simple http proxy server that does some very basic
I want to create some text in a canvas: myText = self.canvas.create_text(5, 5, anchor=NW,
I want to create some up and down buttons using the standard button background
I want to create an ini file to store some settings for my application.
I want to create an NSOutlineView subclass where some of the entries look like
I want to create a folder inside a C# project to contain some configuration
Data table structure is: id1,id2,id3,id4,... (some other fields). I want to create summary query
I want to create a multi-agent simulation model for a real word manufacturing process
I want to create some Gems with parameters lists when i run: my_app --help.

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.