Android11上Cameraactioncrop功能无法工作
创始人
2024-08-20 11:00:45
0

在Android 11上,Camera intent的crop效果已被弃用,因此无法直接使用。相反,可以使用其他方法在应用程序内创建裁剪效果。以下是一个示例代码:

private Uri mCropUri;
private File mFilePath;

private void startCropIntent() {
   Intent cropIntent = new Intent();

   // 创建一个新的裁剪文件
   try {
       mFilePath = createImageFile();
   } catch (IOException e) {
       e.printStackTrace();
   }

   // 将裁剪文件URI绑定到intent上
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
       mCropUri = FileProvider.getUriForFile(this, "com.your.package.fileprovider", mFilePath);
       cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
       cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
   } else {
       mCropUri = Uri.fromFile(mFilePath);
   }

   cropIntent.setAction("com.android.camera.action.CROP");
   cropIntent.setDataAndType(mImageUri, "image/*");
   cropIntent.putExtra("crop", "true");
   cropIntent.putExtra("aspectX", 1);
   cropIntent.putExtra("aspectY", 1);
   cropIntent.putExtra("outputX", 256);
   cropIntent.putExtra("outputY", 256);
   cropIntent.putExtra("scale", true);
   cropIntent.putExtra("return-data", false);
   cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri);

   startActivityForResult(cropIntent, CROP_IMAGE);
}

private File createImageFile() throws IOException {
   // 在应用目录下创建一个新的JPEG文件并返回其路径
   String imageFileName = "JPEG_" + System.currentTimeMillis() + "_";
   File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
   return File.createTempFile(imageFileName, ".jpg", storageDir);
}

其中,createImageFile()方法用于在应用程序目录中创建一个新的JPEG文件,startCropIntent()方法用于启动裁剪意图并获取裁剪后的图像文件的路径。在此示例

相关内容

热门资讯

普及透视!pokemmo脚本最... 普及透视!pokemmo脚本最新版!总是一直总是有辅助工具(有挂规律)-哔哩哔哩1、玩家可以在pok...
关于透视!pokemmo修改器... 关于透视!pokemmo修改器手机版!竟然真的有辅助技巧(真实有挂)-哔哩哔哩1.pokemmo修改...
详情透视!红龙poker有辅助... 详情透视!红龙poker有辅助吗!其实有辅助技巧(有挂方式)-哔哩哔哩运红龙poker有辅助吗辅助工...
详细透视!epoker透视!一... 详细透视!epoker透视!一直有辅助工具(有挂技术)-哔哩哔哩1、epoker透视透视辅助软件激活...
辅助透视!pokemmo辅助官... 辅助透视!pokemmo辅助官网!其实一直总是有辅助工具(有挂攻略)-哔哩哔哩1、实时pokemmo...
详细透视!约局吧怎么看有没有挂... 详细透视!约局吧怎么看有没有挂!确实是真的有辅助软件(有挂秘籍)-哔哩哔哩1、游戏颠覆性的策略玩法,...
揭幕透视!红龙poker辅助平... 揭幕透视!红龙poker辅助平台!都是真的有辅助神器(讲解有挂)-哔哩哔哩进入游戏-大厅左侧-新手福...
关于透视!xpoker辅助助手... 关于透视!xpoker辅助助手!真是有辅助脚本(真的有挂)-哔哩哔哩1、超多福利:超高返利,海量正版...
科普透视!uupoker有透视... 科普透视!uupoker有透视吗!竟然一直都是有辅助插件(真是有挂)-哔哩哔哩1、完成uupoker...
解迷透视!cloudpoker... 解迷透视!cloudpoker怎么开挂!原来一直都是有辅助技巧(存在有挂)-哔哩哔哩1、解迷透视!c...