scsjc Well-Known Member Licensed User Longtime User Sep 16, 2019 #1 I set a background activity with: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width,Activity.height,True)) the image (534px * 949px) is compress on jpg 140kb, real size = 1,45M sometimes have this error: Code: Copy java.lang.OutOfMemoryError: Failed to allocate a 6788208 byte allocation with 4043752 free bytes and 3MB 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 android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize(CanvasWrapper.java:568) at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeResize(CanvasWrapper.java:549) at anywheresoftware.b4a.keywords.Common.LoadBitmapResize(Common.java:1371) at myworldapp.people.com.privado._activity_create(privado.java:463) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196) at myworldapp.people.com.privado.afterFirstLayout(privado.java:106) at myworldapp.people.com.privado.access$000(privado.java:19) at myworldapp.people.com.privado$WaitForLayout.run(privado.java:84) 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:6247) 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) any solution?
I set a background activity with: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width,Activity.height,True)) the image (534px * 949px) is compress on jpg 140kb, real size = 1,45M sometimes have this error: Code: Copy java.lang.OutOfMemoryError: Failed to allocate a 6788208 byte allocation with 4043752 free bytes and 3MB 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 android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize(CanvasWrapper.java:568) at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeResize(CanvasWrapper.java:549) at anywheresoftware.b4a.keywords.Common.LoadBitmapResize(Common.java:1371) at myworldapp.people.com.privado._activity_create(privado.java:463) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196) at myworldapp.people.com.privado.afterFirstLayout(privado.java:106) at myworldapp.people.com.privado.access$000(privado.java:19) at myworldapp.people.com.privado$WaitForLayout.run(privado.java:84) 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:6247) 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) any solution?
R ronell Well-Known Member Licensed User Longtime User Sep 17, 2019 #2 add this to your manifest Code: Copy SetApplicationAttribute(android:largeHeap, "true") this is the easiest workaround for the issue but not optimal Upvote 0
add this to your manifest Code: Copy SetApplicationAttribute(android:largeHeap, "true") this is the easiest workaround for the issue but not optimal
Erel B4X founder Staff member Licensed User Longtime User Sep 17, 2019 #3 You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True)) Upvote 0
You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True))
scsjc Well-Known Member Licensed User Longtime User Sep 17, 2019 #4 I have already done it. ronell said: add this to your manifest Code: Copy SetApplicationAttribute(android:largeHeap, "true") this is the easiest workaround for the issue but not optimal Click to expand... Upvote 0
I have already done it. ronell said: add this to your manifest Code: Copy SetApplicationAttribute(android:largeHeap, "true") this is the easiest workaround for the issue but not optimal Click to expand...
scsjc Well-Known Member Licensed User Longtime User Sep 17, 2019 #5 Erel said: You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True)) Click to expand... I understand perfectly. thank you. Without a doubt this is the solution. Erel said: You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True)) Click to expand... I understand perfectly. thank you. Without a doubt this is the solution. Upvote 0
Erel said: You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True)) Click to expand... I understand perfectly. thank you. Without a doubt this is the solution. Erel said: You are creating a very large image. The memory required is roughly activity width * activity height * 4. Start with eliminating the scale: Code: Copy Activity.SetBackgroundImage(LoadBitmapResize(File.DirAssets,"background.jpg",Activity.width / XUI.Scale,Activity.height / XUI.Scale ,True)) Click to expand... I understand perfectly. thank you. Without a doubt this is the solution.
Erel B4X founder Staff member Licensed User Longtime User Sep 17, 2019 #6 scsjc said: I understand perfectly. thank you. Without a doubt this is the solution. Click to expand... Depending on the image you can go further and downscale it more (further divide it by 2 for example). You need to try it and see how the result looks. Upvote 0
scsjc said: I understand perfectly. thank you. Without a doubt this is the solution. Click to expand... Depending on the image you can go further and downscale it more (further divide it by 2 for example). You need to try it and see how the result looks.