Android 启动系统相机,相册,裁剪图片及6,androidrom开发书籍

本文介绍了Android中启动系统相机、相册以及裁剪图片的方法,包括使用Intent和自定义相册的优缺点。同时,文章讲解了Android 6.0以上系统的动态权限管理,特别是相机和SD卡写权限的检查与请求。最后,提供了裁剪图片的Intent实现和相关开源库推荐。
摘要由CSDN通过智能技术生成

public static Bitmap decodeSampledBitmapFromFile(String pathName, int reqWidth, int reqHeight) {

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

options.inJustDecodeBounds = true;

BitmapFactory.decodeFile(pathName, options);

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

options.inJustDecodeBounds = false;

Bitmap src = BitmapFactory.decodeFile(pathName, options);

// return createScaleBitmap(src, reqWidth, reqHeight, options.inSampleSize);

return src;

}

private static int calculateInSampleSize(BitmapFactory.Options options,

int reqWidth, int reqHeight) {

// 源图片的高度和宽度

final int height = options.outHeight;

final int width = options.outWidth;

int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int halfHeight = height / 2;

final int halfWidth = width / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both

// height and width larger than the requested height and width.

while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {

inSampleSize *= 2;

}

}

return inSampleSize;

}

两种方法的区别

第一种方法获取的bitmap是被缩放的bitmap,第二种方法获取的bitmap是完整的bitmap,实际使用中根据需求情况决定使用哪一种方法。

官网参考地址


怎样启动相册获取我们想要的图片


第一步,通过 Intent.ACTION_GET_CONTENT 这个Intent,并设置相应的type,启动相册。

Intent i = new Intent(Intent.ACTION_GET_CONTENT, null);

i.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, “image/*”);

startActivityForResult(i, INTENT_CODE_IMAGE_GALLERY1);

第二步,在onActivityResult中对返回的uri数据进行处理

  • 需要注意的是:这里我们需要注意是不是MIUI系统,如果不是MIUI系统,我
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值