根据实际要求尺寸显示原图

    技术2022-07-13  67

    public static Bitmap decodeSampledBitmapFromResource( Resources res,int resId,int reqWidth,int reqHeight){ 

    //先通过inJustDecodeBounds=true获取图片尺寸

    BitmapFactory.Option options=new BitmapFactory.Options();

    options.inJustDecodeBounds=true;

    BitmapFactory.decodeResource(res,resId,options);

    //根据图片分辨率以及实际需要的展示尺寸,计算压缩率

    options.inSampleSize=calculateInSampleSize(options,reqWidth,reqHeight);

    //设置压缩率,并解码

    options.inJustDecodeBounds=false;

    return BitmapFactory.decodeResource(res,resId,options);

    }

    Processed: 0.012, SQL: 9