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

Discussion in 'Android Questions' started by Shadow&Max, May 25, 2014.

  1. MoraviaVenus

    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
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at anywheresoftware.b4j.object.JavaObject.RunMethod(
    at b4a.ArtAngels.main._rotateimage(
    at b4a.ArtAngels.main._showcroppingenvironment(
    at b4a.ArtAngels.main._btncropimage_click(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at anywheresoftware.b4a.BA.raiseEvent2(
    at anywheresoftware.b4a.BA.raiseEvent2(
    at anywheresoftware.b4a.BA.raiseEvent(
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(
    at android.view.View.performClick(
    at android.view.View$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.OutOfMemoryError
    at Method)
    ... 23 more

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

    Please, how can I avoid OutOfMemoryError?

    Thank you.
  2. Shadow&Max

    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.
  3. MoraviaVenus

    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice