Jump to content
  • Advertisement
Sign in to follow this  
fredrikhellman

Fast bitmap drawing with .NET and C#

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am writing an application where I need to draw big bitmaps to the screen. I have two huge bitmaps of size up to approx. 3000 x 1000. One is a background bitmap that changes with time, and the other one is a foreground bitmap with transparencies that also changes with time. I would like to draw a portion (say a 1024 x 768 rectangle) of these two to the screen. How do I do this fast with C# and .NET? Is this doomed to fail with the GDI+ API? I have tried using DrawImageUnscaled, but it takes too long time. It takes about 1/20 of a second to draw just one bitmap to the backbuffer. Thanks!

Share this post


Link to post
Share on other sites
Advertisement

Depending on your application, I think you might be better off exploring XNA for this. It generally performs better than GDI+ and using the SpriteBatch utility it's also relatively painless to only display the visible parts of the bitmaps. The only downside is that you're typically stuck with a maximum bitmap size of 2048x2048 for last-generation graphics cards (some support 4096x4096, but you can't really count on that), so you may need to find a way around that or see if there's an alternative approach that fits.

...


On second thought and/or if XNA isn't an option for you, you could also create a 'buffer bitmap' that's as big as your control (viewport) and use Bitmap.LockBits to rapidly transfer imagery from your huge source bitmaps to the buffer bitmap. This way GDI+ only has to draw the buffer bitmap to the window, which should be a lot faster than drawing the huge source bitmaps. Anyway, if it's an option do check out XNA. I think it's just much more suitable for this kind of work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!