BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;// 只读边,不读内容
BitmapFactory.decodeResource(getResources(),
R.drawable.albumart_mp_unknown, options);
options.inJustDecodeBounds = false;
int w = options.outWidth;
int h = options.outHeight;
float ww = 200.0f;
float hh = 200.0f;
int be = 1;
int be1 = (int) (ww / w);
int be2 = (int) (hh / h);
be = be1 < be2 ? be1 : be2;
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;// 设置采样率
options.inPurgeable = true;// 同时设置才有效
options.inInputShareable = true;// 内存不足时可以回收
bm = BitmapFactory.decodeResource(getResources(),
R.drawable.albumart_mp_unknown, options);
android将图片压缩到指定的大小
最新推荐文章于 2022-10-31 14:27:58 发布