当前位置:   article > 正文

Android 选择图片 拍照 并编辑图片_android 调用图片编辑

android 调用图片编辑

调用系统图库并返回图片的url:

  1. Intent intentFromGallery = new Intent();
  2. intentFromGallery.setType("image/*"); // 设置文件类型
  3. intentFromGallery.setAction(Intent.ACTION_PICK);
  4. startActivityForResult(intentFromGallery, IMAGE_REQUEST_CODE);

调用系统相机,传递图片保存地址的文件参数:

  1. // 判断存储卡是否可以用,可用进行存储
  2. if (Tools.hasSdcard()) {
  3. Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  4. File file = new File(Environment.getExternalStorageDirectory(), IMAGE_FILE_NAME);
  5. intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
  6. startActivityForResult(intentFromCapture,CAMERA_REQUEST_CODE);
  7. }

获取回传的图片url,调用系统编辑图片的功能:

  1. Intent intent = new Intent("com.android.camera.action.CROP");
  2. intent.setDataAndType(uri, "image/*");
  3. // 设置裁剪
  4. intent.putExtra("crop", "true");
  5. // aspectX aspectY 是宽高的比例
  6. intent.putExtra("aspectX", 1);
  7. intent.putExtra("aspectY", 1);
  8. // outputX outputY 是裁剪图片宽高
  9. intent.putExtra("outputX", 320);
  10. intent.putExtra("outputY", 320);
  11. intent.putExtra("return-data", true);
  12. startActivityForResult(intent, 2);








声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/174330?site
推荐阅读
相关标签
  

闽ICP备14008679号