【问题标题】:Explanation of Android Code Camera Intent + Cropping ImagesAndroid Code Camera Intent+裁剪图讲解
【发布时间】:2013-07-09 14:37:08
【问题描述】:

当想要在 Android 应用程序中拍照、裁剪和保存图像时,我在我的 Java 中使用以下意图...

            Intent camera=new Intent();
            camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
            camera.putExtra("crop", "true");
            camera.putExtra("outputX",600);
            camera.putExtra("outputY", 600);
            camera.putExtra("aspectX", 1);
            camera.putExtra("aspectY", 1);
            camera.putExtra("scale", true);
            camera.putExtra("return-data", false); 

上述意图效果很好,但是我的 Y 和 X 总是相等的。我正在寻找分解代码以找出指定此内容的内容,以便我可以为我拍摄并希望裁剪的图像进行可定制的 - 最重要的是独立的 - X 和 Y 值......

【问题讨论】:

  • 过去 24 小时内第三次,Android 中没有裁剪Intentcommonsware.com/blog/2013/01/23/…
  • 我相信你不正确......只需在 API 8+ 中自行尝试(这只是我测试过的地方)camera.putExtra("crop", "true"); camera.putExtra("crop", "false"); 将图像保留为其默认纵横比...
  • 无法保证每台 Android 设备(更不用说第三方 ACTION_IMAGE_CAPTURE 应用程序)都会尊重这些未记录的 Intent 附加功能并执行某种裁剪操作。
  • 那么这个设备是特定的吗?或特定于应用程序,什么处理这个意图告诉它做什么......
  • 就记录和未记录的内容而言,如果您发现自己添加了 Intent 附加项,其中的键只是裸字符串,没有在框架中的某处定义为常量(例如,在 @ 987654329@),那么它们没有记录。

标签: android android-camera crop android-camera-intent resize-crop


【解决方案1】:

注意:不建议使用camera.putExtra("crop", "true");...有关详细信息,请参阅上面的评论...方面部分确实解决了我的问题!

            Intent camera=new Intent();

            /** This specifies the action for this intent when it is called. */
            camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

            /** This says yes we can crop the image. */
            camera.putExtra("crop", "true");


            /** These provide the initial dimensions for X and Y. */
            camera.putExtra("outputX",600);
            camera.putExtra("outputY", 600);

            /** These provide the relative aspects. */
            camera.putExtra("aspectX", 1);
            camera.putExtra("aspectY", 1);


            /** These I am unsure about. */
            camera.putExtra("scale", true);
            camera.putExtra("return-data", false); 

所以通过将方面设置为 0 而不是 1,

            /** These provide the relative aspects. */
            camera.putExtra("aspectX", 0);
            camera.putExtra("aspectY", 0);

它们变得彼此独立......

问题解决了!

最终代码

            Intent camera=new Intent();
            camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
            camera.putExtra("crop", "true");
            camera.putExtra("outputX",600);
            camera.putExtra("outputY", 600);
            camera.putExtra("aspectX", 0);
            camera.putExtra("aspectY", 0);
            camera.putExtra("scale", true);
            camera.putExtra("return-data", false); 

【讨论】:

  • 如何获得裁剪图像?
猜你喜欢
  • 2017-02-05
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 2019-10-12
  • 2015-02-02
  • 2021-08-12
  • 2012-01-16
相关资源
最近更新 更多