且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android 获取图片真实宽高

更新时间:2022-06-28 22:50:21

 Resources res = mContext.getResources();
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    BitmapFactory.decodeResource(res, R.drawable.home_common_icon_default, opts);
                    opts.inSampleSize = 1;
                    opts.inJustDecodeBounds = false;

                    int w = opts.outWidth;
                    int h = opts.outHeight;
                    LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:");
                    LogUtil.e("w:" + w);
                    LogUtil.e("h:" + h);
                    int width = DensityUtil.dip2px(mContext, w / 2);
                    int height = DensityUtil.dip2px(mContext, h / 2);
                    LogUtil.e("width:" + width);
                    LogUtil.e("height:" + height);
                    LogUtil.e("getDensity:" + DensityUtil.getDensity(mContext));
                    LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:");

因为默认获取的不是真实宽高,是缩放比例的宽高