DiegoCatalano / Catalano-Framework

Framework
GNU Lesser General Public License v3.0
295 stars 99 forks source link

IllegalStateException #32

Closed LiTe1991 closed 7 years ago

LiTe1991 commented 8 years ago

HI Diego,

I use your nice Framework, but now as I switch to android I get a exception during fastBitmap.toBitmap(). Exception is: java.lang.IllegalStateException: Can't call setPixels() on a recycled bitmap 07-01 09:42:18.942 12791 13040 E AndroidRuntime: at android.graphics.Bitmap.checkRecycled(Bitmap.java:243) 07-01 09:42:18.942 12791 13040 E AndroidRuntime: at android.graphics.Bitmap.setPixels(Bitmap.java:1250) 07-01 09:42:18.942 12791 13040 E AndroidRuntime: at Catalano.Imaging.FastBitmap.toBitmap(FastBitmap.java:854)

Can you help me? Maybe it´s a problem because i recycle the Bitmap to fast?

DiegoCatalano commented 8 years ago

Hello Lite1991,

Sure, glad to help you, There is some filter that I forget to remove the method recycle(). Send me the code plz.

LiTe1991 commented 8 years ago

for(int i = 0; i < scanResult.getTotal(); i++) { try { File outputFile = File.createTempFile("_temp", i + ".img", outputDir); FileUtils.copyFile(scanResult.getFile(i).getPath(), outputFile.getPath()); scanResult.getFile(i).delete(); ScannActivity.results.add(outputFile.getPath()); } catch (IOException e) { e.printStackTrace(); } Bitmap result = BitmapFactory.decodeFile(ScannActivity.results.get(0)); //System.out.println("Width: " + result.getWidth() + " Height: " + result.getHeight());

                        Log.i("IMAGE_START: ", Long.toString(System.currentTimeMillis()));
                        FastBitmap fastBitmap = new FastBitmap(result);

                        Log.i("ZEIT_MESSUNG_START", Long.toString(System.currentTimeMillis()));

                        Crop crop = new Crop(0, 0, WIDTH, HEIGHT);
                        crop.ApplyInPlace(fastBitmap);

                        Rotate rotate = new Rotate(180.00);
                        rotate.applyInPlace(fastBitmap);

                        Resize resize = new Resize((WIDTH * 2) / 3, (HEIGHT * 2) / 3);
                        resize.applyInPlace(fastBitmap);

                        ScannActivity.testResult = fastBitmap.toBitmap();

                        if(fastBitmap != null)
                            fastBitmap.recycle();

                        if(result != null)
                            result.recycle();

I mean in this way it has to work.

DiegoCatalano commented 8 years ago

In the rotate and resize I was calling the method recycle wrong. Now is fixed.

Try to recompile the lib and run.

LiTe1991 commented 8 years ago

Okay thank you, but i get a new Exception durin "FastBitmap fastBitmap = new FastBitmap(...); java.lang.OutOfMemoryError 07-01 15:35:51.250 6557 6612 E AndroidRuntime:
at Catalano.Imaging.FastBitmap.refresh(FastBitmap.java:161) 07-01 15:35:51.250 6557 6612 E AndroidRuntime:
at Catalano.Imaging.FastBitmap.(FastBitmap.java:97)

Or it´s my misstake?

DiegoCatalano commented 8 years ago

The exception "java.lang.OutOfMemoryError" occurs depending on the version of Android, image size and the amount of ram of the smartphone.

LiTe1991 commented 8 years ago

Can i increas the ram size by code?

DiegoCatalano commented 8 years ago

What is the size of the image and the android version ?

LiTe1991 commented 8 years ago

Image information: -11.07 MB

I have android 4.2.2(API 17)

LiTe1991 commented 8 years ago

Hi Diego, I have a general question maybe you cann help me? I want to save a Bitmap as 1 Bit Tiff and edit the EXIF Data, do you know how that works?

DiegoCatalano commented 8 years ago

Currently java doesn't support tiff images, try to use TwelveMonkeys, this lib can support metadata edit.

LiTe1991 commented 8 years ago

Hi Diego,

can you maybe explane why your framework is so powerfull against standard java functions?

DiegoCatalano commented 8 years ago

@LiTe1991 I have solved the out of memory exception.

Just add this code in your Android Manifest file.

android:largeHeap="true"

Anyway, ill port the filters to NDK in the future :)