title: Making a constantly updating Image (WPF)
body: <p>So i am messing around with making a simple AI and stuff with basic C#, and in this project i have alot of points which i've been visualising by making a bitmap.
  This bitmap i have rendered/loaded to an image object in the WPF window.. but my problem is that this is rendered each milisecond, making the framerate quite bad - so how would i make this better?</p>
  
  <p>Can i load it 'constantly'? or should i take another approach? </p>
  
  <p>What i got now is pretty simple but i can show the important parts anyway, taken out of the full class:</p>
  
  <pre><code>private static Bitmap BitMap = new Bitmap(500, 500);
  
  static Graphics GraphicFromBitMap
  {
      get
      {
          return Graphics.FromImage(BitMap);
      }
  }
  
  public static BitmapSource loadBitmapAsImage()
  {
      IntPtr intPtr = BitMap.GetHbitmap();
      BitmapSource bitmapSource = null;
      try
      {
          bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(intPtr,
          IntPtr.Zero, Int32Rect.Empty,
          System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
      }
      finally
      {
          DeleteObject(intPtr);
      }
  
      DeleteObject(intPtr);
  
      return bitmapSource;
  }
  </code></pre>
  
  <p>This is ofcourse only the bitmap part - the actual loading is done the following way:</p>
  
  <pre><code>DispatcherTimer Timer = new DispatcherTimer();
  
  public MainWindow()
  {
  
          this.Timer.Tick += new EventHandler(Timer_Tick);
          this.Timer.Interval = new TimeSpan(0, 0, 0, 1);
  
          this.Timer.Start();
  }
  void Timer_Tick(object sender, EventArgs e)
  {
      WorldMap.Draw();
      map.Source = WorldMap.BitMapSource;
  }
  </code></pre>
  
  <p>This is ofcourse only the important parts - i hope my question is understandable but just to clearify and repeat:</p>
  
  <p>I need a WPF image to update 'every frame' or everytime specific values change.</p>
  
  <p>My question might have been answered before, but i couldn't really find anything that work nor something suiting this instance.</p>
  
  <p>BTW making the timer set off more frequently creates an error with the loading, but the exact error code, i can't remember, and i can't seem to create it again - never the less this probably isn't the most practical way of doing this.</p>
  
  <p>EDIT:</p>
  
  <p>For clarification, this is all i got right now: <a href="http://imgur.com/EIiSRFQ" rel="nofollow">http://imgur.com/EIiSRFQ</a>
  I want nothing fancy - it's just for personal projects playing around with programming and math, and that's alot easier if i can visualize the objects that i am 'moving' in my 2D plane.
  Right now i am playing around with physics and gravity, trying to create a simple solar system with working physics. this is all just side projects to get to know the different tools better when i am too tired to work on my main project.</p>