Voila
Voila

Reputation: 340

createImage returns immutable bitmap in Android when called by another method?

I am building an Android app and I get the following error:

java.lang.IllegalStateException E/AndroidRuntime: at android.graphics.Bitmap.setPixel(Bitmap.java:1407)

for this line image.setPixel(x, y, color);

I am using a library that wraps bitmap with Image, so it calls

Image image = createImage(int x, int y, int z);

...

  //this is a constructor
    private createImage(int width, int height, int imageType) 
    {
        this.bitmap = Bitmap.createBitmap(width, height, this.imageTypeToBitmapConfig(imageType));
    }

I tried createBitmap in my own code and creates a mutable bitmap. But when I try createImage, an immutable image is created. Any ideas?

Upvotes: 1

Views: 149

Answers (1)

Orkun Kocyigit
Orkun Kocyigit

Reputation: 1147

Try changing these in your createImage method:

private createImage(int width, int height, int imageType) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = this.imageTypeToBitmapConfig(imageType);
        options.inMutable=true;
        this.bitmap = Bitmap.createBitmap(width, height, options);
}

Upvotes: 1

Related Questions