在创建位图时,使用密度无关的像素宽度和高度 [英] Use density independent pixels for width and height when creating a bitmap
本文介绍了在创建位图时,使用密度无关的像素宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Bitmap.createBitmap(INT宽度,高度INT,Bitmap.Config配置)方法简单地说,给它的高度和宽度。没有任何迹象表明,如果这些是实际像素或DP像素。
The Bitmap.createBitmap(int width, int height, Bitmap.Config config) method simply says to give it a height and a width. There is no indication if these are actual pixels or dp pixels.
我的问题:
1。)难道这些值DP像素? 2)如果没有,有没有什么办法可以使用DP像素作为高度和宽度参数?
1.) Are these values dp pixels? 2.) If not, is there any way to use dp pixels as parameters for the height and width?
感谢你。
推荐答案
它使用的像素(正常,非DP像素)。使用下面的方法为您的参数转换在DP常规像素:
It uses pixels (regular, not dp pixels). Use the following method to convert your parameters in dp to regular pixels:
public static float dipToPixels(Context context, float dipValue) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}
这篇关于在创建位图时,使用密度无关的像素宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文