public Bitmap decodebitmap(Context context, int imageid) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;// 如果值设为true,那么将不返回实际的bitmap,也不给其分配内存空间,这样就避免了内存溢出。
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
imageid, options);
if (bitmap == null) {
Toast.makeText(context, "bitmap为空", 2).show();//这里能出来,是因为options.inJustDecodeBounds = true;
}
int realwidth = options.outWidth;
int realheight = options.outHeight;
System.out.println("图片真实高度" + realheight + "宽度" + realwidth);
// 计算缩放。
int scal = (int) ((realheight > realwidth ? realwidth : realheight) / 100);
if (sc
Andorid之bitmap里面的压缩总结
最新推荐文章于 2022-01-15 19:17:43 发布
本文介绍了在Android中如何使用BitmapFactory.Options进行Bitmap的压缩处理。在遇到将已有的Bitmap与Options关联的问题后,通过查阅API,了解到应先使用BitmapFactory.decodeByteArray()方法解码字节数组,再进行压缩操作,最后再次调用该方法完成压缩。
摘要由CSDN通过智能技术生成