How to do Hit testing in GDI+ for rotated shapes with real shape measurements (inches)?

前端 未结 2 1889
时光取名叫无心
时光取名叫无心 2021-02-10 18:20

Given I have a canvas that contains many shapes, lets say rectangles for now.

Each shape has a location (inches), size(inches) and rotation angle(degrees).

When

2条回答
  •  野的像风
    2021-02-10 18:28

    Your question is awfully short on details, I can only provide a generic answer. Do it mathematically is the fastest way. Rotation can make that difficult.

    You can solve it slowly but easily by using a hit-test bitmap. Render the shapes to a Bitmap, using the same code you now use to render it to the screen. But now using a color that encodes the shape number. Hit testing is now simple and quick with GetPixel(). Be careful to turn off image enhancement settings, like anti-aliasing. Render it to the screen first and take a good look at the pixels with ZoomIt.

提交回复
热议问题