Android画布位图大小和测量

发布于 2024-10-30 20:02:06 字数 276 浏览 0 评论 0原文

我有一个 PNG 图像,正在 Inkscape 中编辑。它是一个不规则的锯齿状形状,但我需要用它进行碰撞检测。它太大了,无法在其周围制作一个粗略的矩形(它占用的空间超过了标准手机屏幕)。因此,我一直在 INkscape 中在其周围绘制矩形,并记下这些矩形的像素尺寸。

我的目的是使用这些“想象的”矩形的并集进行碰撞检测。然而我的努力遇到了障碍。手机上图像的默认大小似乎与 Inkscape 中的不同。

我想知道对大型不规则物体进行碰撞检测的最佳方法,和/或如何使画布位图测量值与其像素(或毫米)测量值相同。

I have a PNG image that I am editing in Inkscape. It is an irregular, jagged shape, but I need to do collision detection with it. It's too big to make a crude rect around it (it takes up more than a standard phone screen).So I have been drawing rectangles in INkscape around it and noting down the pixel dimensions of the these rects.

My intention is to use the union of these "imaginary" rectangles for collision detection. However my efforts hit a snag. The default size of the image on the phone seems to be different from in Inkscape.

I want to know the best way to do collision detection with a large, irregular object, and/or how to make the canvas bitmap measuremtns the same as its pixel (or mm) measurements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2024-11-06 20:02:06

我建议做的是创建一个等效图像,其中您已将碰撞区域的值定义为 1,将非碰撞区域的值定义为 0(或 0 和 255)。

因此,您将有两个图像,一个是要显示的彩色图像,另一个是要加载的碰撞图像。

然后,您可以通过以下方式检测您是否位于碰撞区域内:

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

另一种解决方案是在处理碰撞图像后创建两个数组,您可以创建一个 Java 应用程序来处理原始图像并首先创建一个包含两行的文本文件第一条线是 x 坐标,第二条线是该对的 y 坐标。

然后,在您的 Android 应用程序中读取此文件,如果您的 x 和 y 存在于该数组中,则为碰撞点。

What I suggest to do is to create an equivalent image where you have defined your collision area with a value of 1, and the non collision area with a value of 0 (or 0 and 255).

So, you will have two images, the colourful one which you will display, and the collision image where you will load.

Then, you can detect if you are inside a collision area with:

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

Another solution is to create two arrays post processing the collision image, you could do that creating a Java application that process your original image and creates a text file with two lines, first line is the x coordinate and the second line is the pair y coordinate.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文