burhanrashid52 / PhotoEditor

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.
MIT License
4.16k stars 992 forks source link

Software rendering doesn't support hardware bitmaps (2.0) #393

Closed fscarponi closed 2 years ago

fscarponi commented 3 years ago

Hi all, maybe the demon is back.... when I use the file chooser for the image, it is correctly loaded (edited etc) but fails on FileSave image

NOTE: all work if image come from the camera, or from APP dedicated storage on the system

image

see #277

You need to check if Android version code is **higher or equal to Q** then you **must** use [Scoped Storage](https://developer.android.com/about/versions/11/privacy/storage). This is a very dramatic change in favor of privacy since now, using scoped storage your app can only access some specific types of files, and will be able to create and access only its own created files without asking for storage permission. It's important to note that the app cannot access other's apps data.

Here is an example that may be useful:

//Is this Android 10+ and requires scoped storage?
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    OutputStream outputStream;
    //Android 10+ already takes care of creating folders if don't exist.
    final String relativeLocation = Environment.DIRECTORY_PICTURES + File.separator + "PhotoEditor";
    ContentValues contentValues = new ContentValues();
    contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "picture_name.jpg");
    contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");
    contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation);
    Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
    try {
        outputStream = context.getContentResolver().openOutputStream(uri);
        yourBitmapToSave.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
} else {
    //save the bitmap normally.. check if folder exists first.
}

Originally posted by @EzequielAdrianM in https://github.com/burhanrashid52/PhotoEditor/issues/277#issuecomment-781357373

fscarponi commented 3 years ago

Founded workaround, create a copy of bitmap on cache, and load the image from there again

image

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 5 days with no activity.