Sign in to follow this  
n4gix

Drawing a bitmap with GDI+ ?

Recommended Posts

Hi,I'm in the proces of making a TCAS gauge using GDI+ and I have a big (?) problem ! My gauge has a background image which works fine and I can draw on it but the drawings are not getting refreshed as I change the drawing (previous layer of drawing stays). So I have to use the Clear() method but... then you have to specify a color and you loose the background image.So on to the next step, after I do Clear() I create an Image object:Image* backgroundbmp as New Image(L"c:directoryfile.bmp");graphics->DrawImage(backgroundbmp, 1, 1 );Compiles fine, gauge starts nicely but... no background image is being drawn. Am I don't something wrong here ? Any help would be strongly appreciated !Bj

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

This way works:Image image(L"AircraftXL2texturevision.bmp");Rect destinationRect(0, 0, 600 * dx, 590 * dy); graphics.DrawImage(ℑ,destinationRect,0, 0, 600, 590, UnitPixel);Using this instead of the Clear() method will "repaint" the background prior to your vector drawing. However, this is very costly in terms of frame rates, because it will engender constant HD activity...A better approach would be to load the bitmap only once, then save it to its own DC. Then, each loop, blitbit the saved DC back to your drawing DC...

Share this post


Link to post
Share on other sites

>A better approach would be to load the bitmap only once, then>save it to its own DC. Then, each loop, blitbit the saved DC>back to your drawing DC...Bill,What would be an advantage of bitblting the bitmap over using DrawImage ?

Share this post


Link to post
Share on other sites

>What would be an advantage of bitblting the bitmap over using>DrawImage ?The image is retained in memory and copied from there.Alternatively, you could simply compile the bitmap as a gauge resource, and use it directly.

Share this post


Link to post
Share on other sites

Hi Bill,You're always there to help ! Really appreciated.I've found a very framerate friendly workaround to my "problem". I dropped the "Clear" method and draw directly on the gauge bitmap (static) but I draw a "FillEllipse" as the CRT main window first, this clears all the drawing on the TCAS screen in one go without that need to redraw the bitmap. Works really well and is very framerate friendly.Thanks for the help !Bj

Share this post


Link to post
Share on other sites

Excellent!That is yet another way to accomplish your goal. Now, extend that idea a bit further and you might consider clearing only the area(s) that change from one cycle to the next...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this