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()方法用于启动裁剪意图并获取裁剪后的图像文件的路径。在此示例

相关内容

热门资讯

aapoker外 挂!aapo... 此外,数据分析德州(aapoker透明挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户aap...
透视辅助!pokerworld... 透视辅助!pokerworld软件,德州私人局脚本(都是是真的有挂)德州私人局脚本软件透明挂微扑克w...
aapoker透明挂!aapo... aapoker透明挂!aapoker插件,(AAPOker)本来是真的有挂,详细教程(有挂透明);人...
透视存在!pokemmo辅助器... 透视存在!pokemmo辅助器脚本下载,德州局透视脚本免费版下载手机版(原来有挂)1、进入游戏-大厅...
aa扑克辅助!aapoker发... aa扑克辅助!aapoker发牌机制,(AAPoKER)都是有挂,详细教程(有挂技巧);aapoke...
透视脚本!哈糖大菠萝破解器,线... 透视脚本!哈糖大菠萝破解器,线上德州的辅助器是什么(一贯是有挂);进入游戏-大厅左侧-新手福利-激活...
aapoker挂!德州aa p... aapoker挂!德州aa poker有外挂吗,(aapokEr)果然真的是有挂,详细教程(有挂技巧...
透视黑科技!拱趴大菠萝万能辅助... 透视黑科技!拱趴大菠萝万能辅助器,德州局怎么透视(总是存在有挂)1、上手简单,内置详细流程视频教学,...
aapoker挂!aapoke... 1、aapoker挂!aapoker外挂教程,(Aapoker)切实真的是有挂,详细教程(有挂介绍)...
透视安装!佛手大菠萝有挂吗,来... 透视安装!佛手大菠萝有挂吗,来玩德州破解器(其实真的是有挂)1、许多玩家不知道佛手大菠萝有挂吗辅助软...