Andorid之bitmap里面的压缩总结

本文介绍了在Android中如何使用BitmapFactory.Options进行Bitmap的压缩处理。在遇到将已有的Bitmap与Options关联的问题后,通过查阅API,了解到应先使用BitmapFactory.decodeByteArray()方法解码字节数组,再进行压缩操作,最后再次调用该方法完成压缩。
摘要由CSDN通过智能技术生成
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 (scal <= 0) {
			scal = 1;
		}
		options.inSampleSize = scal;

		options.inJustDecodeBounds = false;
		bitmap = BitmapFactory.decodeResource(context.getResources(), imageid,
				op
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码莎拉蒂 .

你的鼓励是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值