Bitmap.createBitmap(int width, int height, Bitmap.Config config) 方法只是说给它一个高度和一个宽度。没有指示这些是实际像素还是 dp 像素。
我的问题:
1.) 这些值是 dp 像素吗?
2.)如果没有,有没有办法使用 dp 像素作为高度和宽度的参数?
谢谢。
它使用像素(常规像素,而不是 dp 像素)。使用以下方法将 dp 参数转换为常规像素:
public static float dipToPixels(Context context, float dipValue) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}
Credit: 在Android中将dip转换为px https://stackoverflow.com/questions/8399184/convert-dip-to-px-in-android
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)