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脚本辅助器下载(透视)德州透视插件(辅助)真是是真的有攻略(哔哩哔哩)进入游...
透视总结!sohoo辅助(透视... 透视总结!sohoo辅助(透视)拱趴大菠萝开挂方法(辅助)一直真的是有攻略(哔哩哔哩)1、全新机制【...
透视大纲!hhpoker万能辅... 透视大纲!hhpoker万能辅助器(WePoKer新版本)总是真的是有辅助软件(哔哩哔哩)1、完成h...
透视阶段!pokemmo脚本(... 透视阶段!pokemmo脚本(透视)来玩app 德州 辅助(辅助)原来是有神器(哔哩哔哩)一、来玩a...
透视指南书!wepoker辅助... 透视指南书!wepoker辅助器激活码(HHpoker控制牌)都是存在有辅助脚本(哔哩哔哩)进入游戏...
透视技法!wepoker透视功... 透视技法!wepoker透视功能下载(HHpoker辅助)其实真的是有辅助教程(哔哩哔哩)1、很好的...
透视举措!wepoker轻量版... 透视举措!wepoker轻量版有透视吗(WePoKer最新)原来是真的有辅助app(哔哩哔哩)1、全...
透视模板!pokemmo脚本(... 透视模板!pokemmo脚本(透视)德州真人透视脚本(辅助)真是是有技巧(哔哩哔哩)亲,关键说明,德...
透视妙计!云扑克有透视吗(透视... 您好,pokemmo脚本辅助下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
透视方式!德州来玩辅助器(AA... 透视方式!德州来玩辅助器(AApoker拿好牌)原来是有辅助技巧(哔哩哔哩)1、全新机制【德州来玩辅...