简体   繁体   English

是否可以在不返回到应用程序的情况下裁剪从Android上的Camera捕获的图像?

[英]Is it possible to crop an image captured from the Camera on Android without returning to the app?

The goal is to allow the user to capture a new image with the camera on an Android device. 目的是允许用户使用Android设备上的相机捕获新图像。 I need the final image to be a square. 我需要最终的图像是正方形。 I don't see a way to constrain the size of the capture image without using the Camera class and doing a lot more work. 如果不使用Camera类并进行更多工作,我看不到限制捕获图像大小的方法。

What I would like to be able to do is start the camera activity using the MediaStore.ACTION_IMAGE_CAPTURE Intent action and have the Crop action be performed right after the image is capture. 我想做的是使用MediaStore.ACTION_IMAGE_CAPTURE Intent操作启动相机活动,并在捕获图像后立即执行Crop操作。 I am able to get the desired behavior by using the "com.android.camera.action.CROP" action in onActivityResult when returning from the camera but this returns the user to my app before starting the Crop action. 从相机返回时,我可以通过在onActivityResult使用"com.android.camera.action.CROP"操作来获得所需的行为,但这会在开始Crop操作之前将用户返回到我的应用程序。

To summarize, what I have now is: 总而言之,我现在拥有的是:

My-app -> Camera -> My-app -> Crop

and ideally what I would like is: 理想情况下,我想要的是:

My-app -> Camera -> Crop -> My-app

(If it is possible to tell the image capture intent to use a specific size when opening the camera that would be great if I just missed how to do that.) (如果可以在打开相机时告诉图像拍摄意图使用特定尺寸,那将是很棒的,如果我只是错过了如何做的话。)

Thanks in advance. 提前致谢。

I am able to get the desired behavior by using the "com.android.camera.action.CROP" action in onActivityResult when returning from the camera but this returns the user to my app before starting the Crop action. 从相机返回时,我可以通过在onActivityResult中使用“ com.android.camera.action.CROP”操作来获得所需的行为,但这会在开始Crop操作之前将用户返回到我的应用程序。

Android does not have a CROP Intent . Android没有CROP Intent Few devices will have an activity that supports your undocumented Intent action. 很少有设备可以支持您未记录的Intent操作的活动。

and ideally what I would like is: My-app -> Camera -> Crop -> My-app 理想情况下,我想要的是:我的应用->相机->裁剪->我的应用

You are welcome to use the camera APIs and an image-cropping library to do all of this work yourself. 欢迎您使用相机API和图像裁剪库自己完成所有这些工作。

Or, you are welcome to continue using ACTION_IMAGE_CAPTURE , but do the image-cropping yourself. 或者,欢迎您继续使用ACTION_IMAGE_CAPTURE ,但自己进行图像裁剪。

Or, you are welcome to stick with your existing code, bearing in mind that your image will not be cropped on most Android devices. 或者,请记住,您的图像不会在大多数Android设备上裁剪,因此请坚持使用现有代码。

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

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