saveAsBitmap with error
See original GitHub issueI’m trying to execute saveAsBitmap but I often get this error:
E/ImageFilterView: onDrawFrame: android.graphics.Bitmap@de42880 E/PhotoEditorView: saveFilter: android.graphics.Bitmap@de42880 D/PhotoEditorView: onBitmapLoaded() called with: sourceBitmap = [android.graphics.Bitmap@de42880] onBitmapLoaded() called with: sourceBitmap = [android.graphics.Bitmap@de42880] E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.company.myapp, PID: 24958 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) at android.view.ViewGroup.getAndVerifyPreorderedView(ViewGroup.java:3530) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4001) at android.view.View.draw(View.java:19003) at android.view.ViewGroup.drawChild(ViewGroup.java:4218) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4004) at android.view.View.draw(View.java:19138) at ja.burhanrashid52.photoeditor.PhotoSaverTask.captureView(PhotoSaverTask.java:161) at ja.burhanrashid52.photoeditor.PhotoSaverTask.buildBitmap(PhotoSaverTask.java:104) at ja.burhanrashid52.photoeditor.PhotoSaverTask.saveImageAsBitmap(PhotoSaverTask.java:76) at ja.burhanrashid52.photoeditor.PhotoSaverTask.doInBackground(PhotoSaverTask.java:68) at ja.burhanrashid52.photoeditor.PhotoSaverTask.doInBackground(PhotoSaverTask.java:23) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)
my code is as simple as:
val onSaveBMP: OnSaveBitmap = object: OnSaveBitmap {
override fun onBitmapReady(saveBitmap: Bitmap?) { }
override fun onFailure(e: Exception?) { }
}
mPhoto.saveAsBitmap(onSaveBMP)
really don’t know what is happenin. At first I thought it was something at the moment I tried to use the saveBitmap object, but no… even this code above is causing the crash.
very weird. It is as if the Bitmap can’t be generated for some reason.
Issue Analytics
- State:
- Created 2 years ago
- Comments:35 (21 by maintainers)
Well we really were experiencing different issues, after all. Happy that you found your fix. Mine maybe sometime will come, problably when the native libraries of Android handle better the bitmap inside the canvas method.
I fix the problem. Well, not directly in the library. I’m using my own way to save the image, capturing the photoEditorView view directly. I saw that many faced the same problem (Software rendering doesn’t support hardware bitmaps), so I’ll leave here the solution that worked for me. I believe the captureView method in the library should be modified to fix the problem directly, but I haven’t tried to convert the code to Java since I’m using Kotlin.
Method to capture view:
So to save the image:
Reference: https://stackoverflow.com/questions/58314397/java-lang-illegalstateexception-software-rendering-doesnt-support-hardware-bit