Android bitmap size and size

I have a PNG image that I am editing in Inkscape. This is an irregular, jagged shape, but I need to make a collision detection with it. It is too large to make a coarse sound around it (it takes up more than a standard phone screen). So I draw rectangles in INkscape around it and marking the pixel sizes of these rectangles.

I intend to use a combination of these β€œimaginary” rectangles to detect collisions. However, my efforts fell into the trap. By default, the size of the image on the phone is different from the size of Inkscape.

I want to know the best way to detect collisions with a large irregular object and / or how to make the dimensions of the canvas bitmap the same as the measurements of its pixel (or mm).

+4
source share
1 answer

I suggest creating an equivalent image in which you define your collision zone with a value of 1, and the area without collisions with a value of 0 (or 0 and 255).

So, you will have two images, colorful that you see, and a collision image that you will upload to.

Then you can find out if you are in the collision zone with:

Bitmap collision; collision = BitmapFactory.decodeStream(...yourImage...); collision.getPixel(x,y) 

Another solution is to create two arrays after processing the collision image, you can do this by creating a Java application that processes the original image and creates a text file with two lines, the first line is the x coordinate, and the second line is the y pair.

Then read this file in your Android application, and if your x and y exist in this array, this is the collision point.

0
source

Source: https://habr.com/ru/post/1346762/


All Articles