1
votes

I need to convert GDI methods calls of a relatively complex program into equivalent Direct2D code. For most of the GDI functions I could write equivalent code. But I haven't found any equivalent code for InvertRect. Since the drawing is done dynamically, I can't create (or it will be a performance bottleneck) WICBitmap to get pixels and invert the color.

Can anyone suggest me a good solution, please?

2
Right, that's exactly why you can't find the equivalent, Direct2D doesn't want to do this expensive thing either. Restructure your drawing code so you can reproduce those pixels, but now with a different set of colors. As a bonus it should be much more pleasing to the eye, given the often awful colors that InvertRect() produces.Hans Passant

2 Answers

1
votes

If you want to invert an area that's already been drawn, I believe you can use CreateEffect(CLSID_D2D1Flood) to create an effect that fills with a solid color, then set the effect's color parameter to white, and then use ID2D1DeviceContext::DrawImage with that effect and use D2D1_COMPOSITE_MODE_XOR for the compositeMode parameter.

(You may also need to use transparent white, now that I think of it ... assuming that XOR also operates on the alpha channel. You may need to experiment. Also, it may not work, I haven't tried it.)

-1
votes