简体   繁体   English

从画廊挑选或从相机拍摄的高质量图像

[英]High quality image picked from gallery or captured from camera

I have 3 tasks: 我有3个任务:

  1. Pick image from gallery 从图库中选取图片
  2. Capture image from camera 从相机捕获图像
  3. Crop image from 1 or 2. 从1或2裁剪图像。

The quality of image must be good. 图像质量必须良好。

Are there any solution for my problem? 我的问题有解决方案吗? May be some libraries? 可能是一些图书馆?

Android, by default, actually has all those you enumerated. 默认情况下,Android实际上拥有您枚举的所有内容。

  1. To pick an image from gallery 从图库中选择图像

     Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, FROM_GALLERY); 
  2. To capture image from camera 从相机拍摄图像

     Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePicture, FROM_CAMERA); 
  3. To fetch the results of the intents above and the do the cropping 要获取上述意图的结果并进行裁剪

     @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case FROM_GALLERY: case FROM_CAMERA: { if (resultCode == Activity.RESULT_OK) { Uri selectedImage = data.getData(); Intent cropIntent = new Intent("com.android.camera.action.CROP"); cropIntent.setDataAndType(selectedImage, "image/*"); cropIntent.putExtra("crop", "true"); cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); cropIntent.putExtra("outputX", MAX_WIDTH); cropIntent.putExtra("outputY", MAX_HEIGHT); cropIntent.putExtra("return-data", true); startActivityForResult(cropIntent, PICTURE_CROP); } break; } case PICTURE_CROP: { if (resultCode == Activity.RESULT_OK) { final Bundle extras = data.getExtras(); if (extras != null) { Bitmap photo = extras.getParcelable("data"); // Hurray! You now have the photo as a Bitmap } } break; } } } 

Update: 更新:

According to this post you should not use com.android.camera.action.CROP since this does not exist in all devices. 根据这篇文章,您不应该使用com.android.camera.action.CROP因为它并非在所有设备中都存在。 In that post, he also enumerated alternatives which I will also list here: 在那篇文章中,他还列举了一些替代方法,我还将在这里列出:

  1. https://github.com/lvillani/android-cropimage https://github.com/lvillani/android-cropimage
  2. https://github.com/biokys/cropimage https://github.com/biokys/cropimage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM