使用自定义方法
mBmpDial = decodeResource( getResources(),
R.drawable.android_clock_dial );
private Bitmap decodeResource(Resources resources, int id) {
TypedValue value = new TypedValue();
resources.openRawResource( id, value );
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inTargetDensity = value.density;//获取当前手机运行环境的手机密度
opts.inScaled = false;
return BitmapFactory.decodeResource( resources, id, opts );
}
``
自定义方法加载图片资源
该博客介绍了一种自定义的方法来从资源中解码并加载Android应用中的图片。通过使用`TypedValue`和`BitmapFactory.Options`,该方法考虑了手机密度,确保图片不被缩放,并正确地适应目标设备的密度。

被折叠的 条评论
为什么被折叠?



