在不同的设备裁剪图像 [英] Crop image on different devices

查看:184
本文介绍了在不同的设备裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用相机拍摄的图片和裁剪。这对新设备的伟大工程(与第二code)符合本code我对社会的维基找到:

I want to take a picture with the camera and crop it. This works great (with the second code) on newer devices with this code I found on the community wiki:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.gallery", "com.android.camera.CropImage");

在某些Android版本,包括最新,com.android.gallery不存在了。您需要使用此则:

On some Android versions, including the newest, com.android.gallery doesn't exist anymore. You need to use this then:

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.CropImage");

我当然要支持老设备了。什么才叫有某些Android版本?有人可以给我一个API级?或者有没有在Android源代码的任何最终constances,我可以用它来选择的意图正确的字符串?

Of course I want to support older devices too. What is meant with "some Android versions"? Can someone give me an API level? Or are there any final constances in the Android source which I can use to select the correct Strings for the intent?

推荐答案

我找到了一个更好的code这个问题。这,这里将搜索的应用程序,其能够裁剪图像并启动找到的第一个。希望帮助别人。

I found a better code for this problem. This here will search for apps which are able to crop images and start the first that is found. Hope that help someone.

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

List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(cropApps, 0);
int size = list.size();

if (size == 0) 
{           
    Toast.makeText(context, "Can not find image crop app", Toast.LENGTH_SHORT).show();      
    return null;
} 
else 
{
    ResolveInfo res = list.get(0);

    Intent intent = new Intent();
    intent.setClassName(res.activityInfo.packageName, res.activityInfo.name);

    intent.setData(imageCaptureUri);
    intent.putExtra("outputX", 96);
    intent.putExtra("outputY", 96);
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);

    startActivityForResult(intent, CROP_FROM_CAMERA);
}

这篇关于在不同的设备裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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