public static Bitmap decodeBitmap(String path, int displayWidth, int displayHeight){ BitmapFactory.Options op = new BitmapFactory.Options(); op.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(path, op); //获取尺寸信息 //获取比例大小 int wRatio = (int)Math.ceil(op.outWidth/(float)displayWidth); int hRatio = (int)Math.ceil(op.outHeight/(float)displayHeight); //如果超出指定大小,则缩小相应的比例 if(wRatio > 1 && hRatio > 1){ if(wRatio > hRatio){ op.inSampleSize = wRatio; }else{ op.inSampleSize = hRatio; } } op.inJustDecodeBounds = false; bmp = BitmapFactory.decodeFile(path, op); return Bitmap.createScaledBitmap(bmp, displayWidth, displayHeight, true); }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。