簡體   English   中英

作物功能適用於棉花糖或以上,但不適用於低於棉花糖

[英]Crop functionality is working on marshmallow or above but do not work below marshmallow

圖片已裁剪,可以在棉花糖及以上的列表中成功查看,但在棉花糖以下則無法正常工作。 我認為,如果我們選擇谷歌照片進行裁剪,而不是在其他情況下可以正常工作。

同樣在我的情況下,已經提供了運行時權限。

代碼以單擊相機中的圖像

Uri fileUri;

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(getExternalCacheDir(), String.valueOf(System.currentTimeMillis()) + ".jpg");
    fileUri = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
    startActivityForResult(intent, 501);

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {

        case 501:
            isFromOneActivityToAnother = true;
            ImageCropFunction();
            //startCropImageActivity(fileUri);
            break;

        case 502:
            uriImageListForServer.add(getImageContentUri(getApplicationContext(), new File((fileUri + "").substring(7, (fileUri + "").length()))));
            break;
    }
}

public void ImageCropFunction() {
    try {
        isFromOneActivityToAnother = true;
        Intent CropIntent = new Intent("com.android.camera.action.CROP");
        CropIntent.setDataAndType(fileUri, "image/*");
        CropIntent.putExtra("crop", "true");
        CropIntent.putExtra("outputX", 2048);
        CropIntent.putExtra("outputY", 2048);
        CropIntent.putExtra("scaleUpIfNeeded", true);
        CropIntent.putExtra("return-data", true);

        startActivityForResult(CropIntent, 502);
    } catch (ActivityNotFoundException e) {

    }
}

public static Uri getImageContentUri(Context context, File imageFile) {
    String filePath = imageFile.getAbsolutePath();
    Cursor cursor = context.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Images.Media._ID},
            MediaStore.Images.Media.DATA + "=? ",
            new String[]{filePath}, null);
    if (cursor != null && cursor.moveToFirst()) {
        int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
        cursor.close();
        return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
    } else {
        if (imageFile.exists()) {
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);
            return context.getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            return null;
        }
    }
}

圖片已裁剪,可在棉花糖列表中成功查看

不,不是的。 它恰好在您測試的一台設備上工作。 Android沒有CROP Intent 市場上成千上萬的設備中可能只有少數設備。

有許多可用於Android的圖像裁剪庫 使用一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM