Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

saveAsBitmap with error

See original GitHub issue

I’m trying to execute saveAsBitmap but I often get this error:

E/ImageFilterView: onDrawFrame: E/PhotoEditorView: saveFilter: D/PhotoEditorView: onBitmapLoaded() called with: sourceBitmap = [] onBitmapLoaded() called with: sourceBitmap = [] E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process:, PID: 24958 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done( at java.util.concurrent.FutureTask.finishCompletion( at java.util.concurrent.FutureTask.setException( at at android.os.AsyncTask$SerialExecutor$ at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.get( at android.view.ViewGroup.getAndVerifyPreorderedView( at android.view.ViewGroup.dispatchDraw( at android.view.View.draw( at android.view.ViewGroup.drawChild( at android.view.ViewGroup.dispatchDraw( at android.view.View.draw( at ja.burhanrashid52.photoeditor.PhotoSaverTask.captureView( at ja.burhanrashid52.photoeditor.PhotoSaverTask.buildBitmap( at ja.burhanrashid52.photoeditor.PhotoSaverTask.saveImageAsBitmap( at ja.burhanrashid52.photoeditor.PhotoSaverTask.doInBackground( at ja.burhanrashid52.photoeditor.PhotoSaverTask.doInBackground( at android.os.AsyncTask$ at at android.os.AsyncTask$SerialExecutor$  at java.util.concurrent.ThreadPoolExecutor.runWorker(  at java.util.concurrent.ThreadPoolExecutor$  at

my code is as simple as:

val onSaveBMP: OnSaveBitmap = object: OnSaveBitmap {
                    override fun onBitmapReady(saveBitmap: Bitmap?) { }
                    override fun onFailure(e: Exception?) { }


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:open
  • Created 2 years ago
  • Comments:35 (21 by maintainers)

github_iconTop GitHub Comments

anderbytescommented, Oct 10, 2021

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.

jserickskcommented, Oct 10, 2021

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:

    fun captureView(view: View, window: Window, bitmapCallback: (Bitmap) -> Unit) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Above Android O, use PixelCopy
            val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
            val location = IntArray(2)
                Rect(location[0], location[1], location[0] + view.width, location[1] + view.height),
                    if (it == PixelCopy.SUCCESS) {
        } else {
            val bitmap = Bitmap.createBitmap(
                view.width, view.height, Bitmap.Config.RGB_565
            val canvas = Canvas(bitmap)

So to save the image:

captureView(photoEditorView, window) { bitmap ->
// Operation to save the image normally with Bitmap


Read more comments on GitHub >

github_iconTop Results From Across the Web

Createimage giving error while saveasbitmap works - Inventor
I'm trying to show the view from inventor in another interface, but I can seem to find a way to use the createimage...
Read more >
Saving bitmap/"screenshot" of form not working when form is ...
When I run SaveAsBitmap by pressing the button, the form and its elements is correctly saved as a bmp file (just as if...
Read more >
SaveAsBMP Method - ComponentSource CDN
SaveAsBMP(String FileName, Short sImageIndex) ... When an error occurs and IfThrowException property is TRUE, an exception will be thrown.
Read more >
Can't save as bitmap - CorelDRAW Graphics Suite X8
How to disable the request to create a Corel account on every start of Corel Draw? Suggested Answer over 6 years ago. JoshStead....
Read more > - ImageJ
cancelPressed()) return; saveAsBitmap = bd.yesPressed(); } width = ip. ... printStackTrace(); IJ.error("Error writing EPS file " + dir + name); } IJ.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found