八天 自定义控件 使用贴图加载图片非原图片大小 decodeResource

Ichjns

关注

阅读 85

2022-03-11

使用自定义方法

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 );
    }

``

精彩评论(0)

0 0 举报