How do I implement layer with GDI?
I want to implement a rubber function just li开发者_如何学Goke photoshop, but I hope the rubber just to erase the shapes that drawed on background without modifying the background. Now the background is a image so I can't use the brush with the single color.
You need to store each layer of the image in its own buffer, and then combine them to output it. So the background would be in one Image object and the shape would be in another Image object. When you get the WM_Paint message, you would have to combine both images into one and output that (or you would have to have the images pre-combined in a third Image object in memory).
If you just want to draw simple lines/shapes like a rubber-banding box, the old-fashioned way is to use exclusive-or painting. This "inverts" the colours where it is drawn, so drawing the same shape a second time erases it and returns the original image.
These days computers are much more powerful so we tend (as Dave Markle has said) to just combine two separate images onto the screen (you just have to store the actual image you are editing in an offscreen bitmap). This allows you to draw the overlay using any colour/transparency, so you can make it look much nicer.
精彩评论