我有一个 100x100 的图像和一些我想放置的坐标,它们与图像的比例相同。我用 加载图像BitmapFactory.decodeResource()
,它被缩放到 133x133。但是当我使用TypedValue.applyDimension()
withTypedValue.COMPLEX_UNIT_DIP
来缩放坐标时,我得到的缩放因子是 x2 而不是 x1.33。
如何确保我的坐标和图像按相同的量缩放?
我有一个 100x100 的图像和一些我想放置的坐标,它们与图像的比例相同。我用 加载图像BitmapFactory.decodeResource()
,它被缩放到 133x133。但是当我使用TypedValue.applyDimension()
withTypedValue.COMPLEX_UNIT_DIP
来缩放坐标时,我得到的缩放因子是 x2 而不是 x1.33。
如何确保我的坐标和图像按相同的量缩放?
I'm testing on an xhdpi device, but I didn't have any xhdpi resources, so the decodeResource()
was grabbing my hdpi resources and scaling up by 2/1.5=1.33.
The correct solution seems to be that you should specify your coordinates in the same scale as your mdpi resources, and ensure that you scale your alternate sized drawables with the same ratio that android expects, then use TypedValue.applyDimension()
to scale your coordinates.