[.net] Need help with GDI+

Started by
4 comments, last by Headkaze 16 years, 1 month ago
I'm currently working on a chip 8 emulator with GDI+ and have run into a problem. The resolution has to be 64x32 pixels, and so I made a bitmap thats 64x32. The problem is that this creates a tiny bitmap that I can barely see. Is there any way to increase the size of the bitmap will maintaining the same 62x32 resolution?
Advertisement
When you blit the surface to your window, use StretchBlt (Or whatever the .NET version is). The data buffer is still 64x32, you're just scaling it up to display it.
When you call DrawImage, just specify larger destination dimensions while keeping the source rectangle 64x32.
Mike Popoloski | Journal | SlimDX
You could also use a PictureBox with the bitmap assigned to it's Image property. Then just set it's SizeMode to StretchImage. When you want the PictureBox to update after you've drawn to the bitmap just call it's Invalidate method.

Not sure of the performance comparisons between these different methods. If you do use this method use DrawImageUnscaled instead as it's faster than DrawImage. It would be interesting to get out the old System.Diagnostics.Stopwatch and compare the speeds.
Quote:Original post by Headkaze
You could also use a PictureBox with the bitmap assigned to it's Image property. Then just set it's SizeMode to StretchImage. When you want the PictureBox to update after you've drawn to the bitmap just call it's Invalidate method.

Not sure of the performance comparisons between these different methods. If you do use this method use DrawImageUnscaled instead as it's faster than DrawImage. It would be interesting to get out the old System.Diagnostics.Stopwatch and compare the speeds.


thanks.
I will test both methods to see which one is faster.

One more question i had was when I draw a bitmap with the same color over another bitmap, the bitmap darkens. Should I clear the bitmap before everytime it is drawn to the form or is this method too slow?
Quote:Original post by ed209
I will test both methods to see which one is faster.

One more question i had was when I draw a bitmap with the same color over another bitmap, the bitmap darkens. Should I clear the bitmap before everytime it is drawn to the form or is this method too slow?


You can use Graphics.Clear() to clear it. But a better way would be to set the alpha byte when writing the pixels directly.

This topic is closed to new replies.

Advertisement