Android Question File Rotation... Can't Get It Done!

MoraviaVenus

Member
Licensed User
Hi Erel,

I have used your RotateImage function from post #8, but when I run my app on some devices (e.g. LG G Pad tablet or Sony Xperia E3), I get OutOfMemoryError. On the other hand, on some another devices (e.g. Sony Xperia Z3 or high end Samsung phone) works smoothly.

Downsampling image due to lack of memory.
main_rotateimage (B4A line: 903)
NewImage = bmp.RunMethod("createBitmap", Array
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at b4a.ArtAngels.main._rotateimage(main.java:2865)
at b4a.ArtAngels.main._showcroppingenvironment(main.java:3155)
at b4a.ArtAngels.main._btncropimage_click(main.java:891)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18471)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:809)
at android.graphics.Bitmap.createBitmap(Bitmap.java:786)
at android.graphics.Bitmap.createBitmap(Bitmap.java:718)
... 23 more

My aim is to rotate high resolution images 90 degrees clockwise.

Please, how can I avoid OutOfMemoryError?

Thank you.
 

Shadow&Max

Active Member
Licensed User
It's really tough to do. You're taking a high res picture and loading it into memory. Then you're rotating that so you're creating another bitmap in memory. They're both huge in size. And there's a lot going on in the phone as well. I bet that the phones that work have more internal memory than the group that doesn't. 16GB on a phone isn't the amount of usable memory you have to work with... it's just the overall storage space.

This is a guess, but I remember that when I was playing with this, certain devices worked and others didn't. The ones with more workable memory seemed not to falter.
 

MoraviaVenus

Member
Licensed User
Hi Shadow&Max,

thank you for diagnostics.

Please, is there other approach, how can I rotate image outside of memory?

My code is crashing on line:

NewImage = bmp.RunMethod("createBitmap", Array(original, 0, 0, original.Width, original.Height, matrix, True))​

... where NewImage is global variable.

Thank you.
 
Top