【问题标题】:Crop image on different devices在不同设备上裁剪图像
【发布时间】:2014-02-25 08:04:42
【问题描述】:

我想用相机拍照并裁剪。使用我在社区 wiki 上找到的代码,这在较新的设备上效果很好(使用第二个代码):

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

在某些 Android 版本(包括最新版本)上,com.android.gallery 不再存在。然后你需要使用它:

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

当然,我也想支持旧设备。 “某些 Android 版本”是什么意思?有人可以给我一个 API 级别吗?或者我可以使用 Android 源代码中的任何最终常量来为意图选择正确的字符串?

【问题讨论】:

    标签: android android-intent android-gallery


    【解决方案1】:

    某些设备不支持裁剪,这意味着他们的图库应用程序没有构建它。最好的解决方案是在您的应用程序中构建裁剪机制。这是一个很好的开源裁剪器:

    https://github.com/edmodo/cropper

    【讨论】:

    • 很棒的图书馆!谢谢你:)
    【解决方案2】:

    我为这个问题找到了更好的代码。这将搜索能够裁剪图像并启动第一个找到的应用程序。希望对某人有所帮助。

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 1970-01-01
      • 2013-02-02
      • 2015-08-10
      • 2022-01-23
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2015-02-02
      相关资源
      最近更新 更多