Android Question java.lang.OutOfMemoryError

D

Deleted member 103

Guest
Hi,

This code causes an error message to multiple devices.
Can I improve something in the code?
B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("frm7Karten")
   
    'Hindergrundbild laden
    Dim bmp As Bitmap
    Dim bmpExt As BitmapExtended
    bmpExt.Initialize("")
    bmp=bmpExt.rotateBitmap(LoadBitmapSample(File.DirAssets, Main.strOldBackground & ".jpg",Activity.Width,Activity.Height),90)
    Activity.SetBackgroundImage(bmp)

error message-report:
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
at android.graphics.Bitmap.createBitmap(Bitmap.java:586)
at com.rootsoft.bitmaplibrary.BitmapLibrary.rotateBitmap(BitmapLibrary.java:363)
at fg.Solitario_free.m7karten._activity_create(m7karten.java:343)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at fg.Solitario_free.m7karten.afterFirstLayout(m7karten.java:98)
at fg.Solitario_free.m7karten.access$100(m7karten.java:16)
at fg.Solitario_free.m7karten$WaitForLayout.run(m7karten.java:76)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
 

margret

Well-Known Member
Licensed User
Longtime User
Try it like this:

B4X:
Dim bmp As Bitmap
Dim bmpExt As BitmapExtended
bmpExt.Initialize("bmpExt")
bmp = LoadBitmapSample(File.DirAssets, Main.strOldBackground & ".jpg", Activity.Width, Activity.Height)
Activity.SetBackgroundImage(bmpExt.rotateBitmap(bmp, 90))
 
Last edited:
Upvote 0
D

Deleted member 103

Guest
Hi margret,

Unfortunately, this does not bring the desired effect, the error message still comes.
I think the bitmap is too large.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Which dimensions do the image have in original? Width*Height

where do you get the image from? Download over internet? or are they part of your Assets?
If you download the files you could call a phpscript instead of downloadding directly for example which reads the original image and write it down to a new, smaller, one and your apps get the smaller imager as return from that script. so you can make the image smaller and the "cpu power needed is transferred to the webserver.
In this case you also would have the advantage that you can do more with this image...
Maybe put a watermark on it, or a text on the image.
Or even rotate the original image to it´s right position so that the app dont need to rotate it.
 
Last edited:
Upvote 0
D

Deleted member 103

Guest
Hi DonManfred,

die Bitmaps sind alle in dem Assets ordner. Ich habe jetzt alle Bitmaps als Vertikale und Horizontale erstellt, somit muss ich in der App die Bitmaps nicht mehr um 90 grad drehen.

the bitmaps are all folders in the Assets. I have now created all the bitmaps as vertical and horizontal, so I have in the app to bitmaps no longer rotate by 90 degrees.
 
Upvote 0
Top