c# - How to delete an image from Graphics -
suppose use drawimage few times draw bunch of images.
e.graphics.drawimage(newimage, destrect);
how can delete specific image graphics paper drew on? there specific function can use deletion?
i have tried dispose , rectangle.empty, don't delete image drew on paper.
first of all, there's no concept of "delete object" in gdi+ graphics. have redraw the entire client area in every frame. should keep list of objects , states in memory , redraw entire surface in every frame. beware though, can lead flickers , not-so-smooth user experience. here few tips avoid these:
make sure form or usercontrol has
doublebufferedproperty set true. result in far smoother animation otherwise.never ever call
creategraphics()reference graphics object in drawing loop. update list of objects , states in loop , callinvalidate()on control/form , drawing process inpaintevent.one overload of
invalidate()allows specify rectangle needs invalidated (redrawn). can pass "safe" rectangle around bouncing ball's current position (say 20 pixels wider/taller ball size) agrument , draw portion inpaintevent.to further increase performance can keep auxilary information such scores, player names etc. outside actual "game board" , use normal labels/textboxes them instead of drawing.
Comments
Post a Comment