通过保持宽高比在Android中裁剪图片 [英] Cropping Pictures in Android by keeping Aspect Ratio

查看:228
本文介绍了通过保持宽高比在Android中裁剪图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码启动裁剪活动,并将裁剪后的图片作为onActivityResult中的数据返回.这样就可以了.

I use this code to start the crop activity and i get the cropped picture as data in onActivityResult back. So this works fine.

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
            intent, 0);

    int size = list.size();

    if (size == 0) {
        Toast.makeText(this, "Can not find image crop app",
                Toast.LENGTH_SHORT).show();
        return;
    } else {
        intent.setData(mImageCaptureUri);

        intent.putExtra("outputX", 200);
        intent.putExtra("outputY", 200);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        Intent i = new Intent(intent);
        ResolveInfo res = list.get(0);

        i.setComponent(new ComponentName(res.activityInfo.packageName,
                res.activityInfo.name));

        startActivityForResult(i, CROP_FROM_CAMERA);

这是用于将图像裁剪为200x200大小的代码,与我在裁剪活动中选择的宽高比无关.我担心的是,我想要在活动中使用矩形选择的宽高比,而不是通过将数字200和200固定为固定比例.

This is the code for cropping the image into the size of 200x200, dont matter which aspect ratio I chose at the cropping activity. My concern is, that i want THE aspect ratio which i choose with the rectangle in the activity, not a fixed by putting the numbers 200 and 200.

但是当我注释掉这两行时,我的程序将强制关闭....

But when I comment out these two lines, my program will force close....

是否有任何解决方案,可以精确地裁切我在裁切活动中选择的图片部分,并保持放置在图片上的矩形的长宽比不变? 我必须附加哪些数据?需要帮助!

Are there any solutions for cropping exact to the part of the picture which i chose in the crop activity with keeping the aspect ratio from the rectangle I placed on my picture? Which data do I have to put as extras? Need Help!

推荐答案

如何在android

使用不能裁剪成正方形以外的任何形状 内置的Android裁剪处理 (com.android.camera.action.CROP).

Cropping to anything other than a square shape is not possible using the built-in Android cropping handling (com.android.camera.action.CROP).

在下一个线程中查看OP的回复-您可能有解决方案.

Look at the OP's reply in the next thread - and you might have a solution.

此线程也有一些好的建议:

This thread also has some good suggestions:

这篇关于通过保持宽高比在Android中裁剪图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆