Extract objects bounds from png image in c# application

72 Views Asked by At

I have a transparent image of Pacman Level Map as Pacman PNG Level

I want to extract wall bounds from image to so i can check if player (Pacman) [which is a GIF image that has rectangular bounds ( Width , Height )] intersected with one of the walls inside the png image.

I'm down to manually select walls from the image if there is a manual way of doing this. ( Instead of cutting it shape by shape using photoshop )

Any automatic / manual way to do this?

I searched about this a lot but all i could get is ( bitmap the image ). i tried it but didn't work! ( even used chat gpt's bitmap code )

1

There are 1 best solutions below

4
JonasH On

No. You can easily get the width/height of a bitmap. But if you need the coordinate of the walls you need to do it yourself.

One option is to just do intersection on the pixel level. For each pixel in the player model, check if any visible pixel intersects the wall. This is very simple, and should probably perform well enough.

Another option would be to vectorize the image. This would be quite a lot of work to do yourself, but I expect there to be libraries available. See https://softwarerecs.stackexchange.com/ if you want recommendations.

But if you want to implement a packman clone you probably want the center lines in each corridor, and restrict movement along these lines. There are image processing techniques that may be able to do this, but I would expect the simplest option would be to just create these lines for hand. At least if you only have one map. You should then be able to combine the lines to form a graph to allow full movement.