Android Question bitmap rotate problem

yaniv hanya

Active Member
Licensed User
img1.Bitmap=LoadBitmap(path, f)
works fine
img1.Bitmap=LoadBitmap(path, f).Rotate(90)
give me the next error

java.lang.OutOfMemoryError: Failed to allocate a 79629324 byte allocation with 4184592 free bytes and 48MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
at android.graphics.Bitmap.createBitmap(Bitmap.java:856)
at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Rotate(CanvasWrapper.java:578)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.main._showimg(main.java:408)
at b4a.example.main._activity_resume(main.java:511)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at b4a.example.main.afterFirstLayout(main.java:110)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Error occurred on line: 50 (Main)
java.lang.NullPointerException: Attempt to read from field 'java.lang.Object anywheresoftware.b4a.shell.Shell$RemoteObject.value' on a null object reference
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:725)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at b4a.example.main.afterFirstLayout(main.java:110)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Error occurred on line: 72 (Main)
java.lang.Exception: array not expected...

eny idea why?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

yaniv hanya

Active Member
Licensed User
I'm developing on Lenovo Tab 7 with 2 Gigabytes and Android 7.0
The device is special for development. Nothing ran on him except the b4a bridge
And I'm trying to spin a 5 megapixel image
Why is memory running out?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
And I'm trying to spin a 5 megapixel image
Spin implies animation (cf rotate could also be a one-off rotation). If you are animating, and using B4X UI routines, consider handballing the rotations to the GPU with:

upload_2019-10-11_18-4-11.png


but it'd still be nice to scale that 5 megapixel image to match the screen resolution.
 
Upvote 0

yaniv hanya

Active Member
Licensed User
I used the LoadBitmapResize it works great.
But just for the sake of understanding, is the operation of rotate is so heavy?
Because I never had a problem with just displaying the pictures even with big pictures.
 
Upvote 0
Top