public static final int NONE = 0;
public static final int PHOTOHRAPH = 1;// 拍照
public static final int PHOTOZOOM = 2; // 缩放
public static final int PHOTORESOULT = 3;// 结果
public static final String PHOTO_ACTION_CROP = "com.android.camera.action.CROP";
public static final String IMAGE_UNSPECIFIED = "image/*";
public static int CropSize = 400;// by default
private File photoSaveFile;
public void TakePhoto(String type, String path, String fName, String size) {
myRequetPermissionCarmer(type, path, fName, size);
}
private void myRequetPermissionCarmer(String type, String path, String fName, String size) {
//targetSdkVersion 26 以上,先判断有没有权限
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
Log.e("AriTest", "没有权限开始获取:");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1002);
}else {
Log.e("AriTest", "有权限开始拍照:");
Log.e("AriTest", "TakePhoto:" + type + "/" + path + "/" + fName);
CropSize = Integer.valueOf(size);// 安卓端不宜经常改,由Unity指定裁剪大小
photoSavePath = path; //图片地址
fileName = fName;
photoSaveFile = new File(getExternalCacheDir(), System.currentTimeMillis() + ".jpg"); //裁剪图片保存地址
// 通过传过来的type 在这里判断是打开本地相册还是直接照相
if (type.equals("takePhoto")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
AndroidStudio选择及裁剪图片
最新推荐文章于 2025-03-12 15:48:32 发布