android 拍照和选择相册图片剪切
来源:互联网 发布:程序化交易编程语言 编辑:程序博客网 时间:2024/05/16 06:41
拍照剪切步骤:
- 新建临时文件
- 启动相机
- 拍照后启动剪切
- 返回剪切结果
新建临时文件
private Uri imageUri;//拍照后剪切用到Uriprivate String picFileFullName;//剪切后图片路径
File outputImage = new File(Environment.getExternalStorageDirectory(), "output_image.jpg");picFileFullName = outputImage.getAbsolutePath();try {if (outputImage.exists()) {outputImage.delete();}outputImage.createNewFile();} catch (Exception e) {e.printStackTrace();}imageUri = Uri.fromFile(outputImage);
启动相机
这个过程有些手机会销毁activity,拍照后回调直接崩溃。自行解决。
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);startActivityForResult(intent, TAKE_PHOTO);
拍照后启动剪切
private void cropImage(Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", true); intent.putExtra("scale", true); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX outputY 是裁剪图片宽高 intent.putExtra("outputX", 650); intent.putExtra("outputY", 650); intent.putExtra("return-data", false); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "output_image.jpg")));//剪切后直接输出到这个文件,就是替换了刚开始新建的文件。 startActivityForResult(intent, PHOTO_CUT_RESULT); }
返回剪切结果
picFileFullName剪切后的图片路径
选择相册图片剪切
- 新建临时文件
- 启动相册
- 选择图片后启动剪切
- 返回剪切结果
新建临时文件
步骤和拍照一样
启动相册
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");startActivityForResult(intent, IMAGE_PICK_CODE);
Intent说明:
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
这个缺点是如果有图片是同步到google相册的话,图库里面能看到一个auto backup的目录,点进去选图片的话是无法获取到图片的路径的。Google被墙了的。不考虑这么多。
ACTION_GET_CONTENT
在4.4版本中返回图片的URI:content://com.Android.providers.media.documents/document/image:3951类似这样。因此需要判断系统版本进行URI转换。
选择图片后启动剪切
跟拍照剪切一样,剪切后输出的文件直接覆盖开始新建文件
返回剪切结果
picFileFullName剪切后的图片路径
0 0
- android 拍照和选择相册图片剪切
- Android 从相册和拍照选择图片
- Android——拍照、剪切、得到图片/从相册中选择照片(api19以上和以下有区别)
- 从相册或拍照选择图片并剪切
- Android 拍照和相册选择
- android 选择图片 相册选择 马上拍照
- Android 选择图片 相册选择 马上拍照
- Android图片裁剪(拍照和从相册选择)
- Android从相册选择图片和调用系统摄像头拍照
- android 拍照和相册选择照片之后。剪裁图片。
- Android 拍照/相册 选择图片工具
- Android 拍照、从相册选择图片
- android 拍照剪切图片
- android 拍照 图片剪切
- 拍照和从相册选择图片 截图
- 拍照和从相册选择图片
- 拍照和从相册选择图片
- anroid 拍照调用相册 剪切编辑图片
- Hibernate入门配置详解及例子
- mongodb 索引建立问题
- DataTables+Struts+Ajax技术的文件下载实现
- 第14周 《C语言及程序设计》实践参考——工资的排序
- 开发中最常用的GitHub上 优秀的 Android 开源项目整理(精品)
- android 拍照和选择相册图片剪切
- 深度卷积网络CNN与图像语义分割
- 使用strace, ltrace寻找故障原因的线索
- nginx + lua + redis
- iOS支付宝1分钟集成,使用方法封装。超级好用
- 代码中获取md签名值,防二次打包
- Light 1045 Digits of Factorial 【数论】
- 常用系统操作响应时间表
- c# 根据图像获取图像的扩展名