Hi,
I have a Background Image (Png) which is nearly the size of my Screen.
Now I want to overlay 31 other PNG.
My first try was to create 32 ImageViews all of the same size. This worked for a few pics but than I ran out of memory.
My next try was the same but loading the Image with VBBitmap Lib – this worked but the quality of some pictures is so bad….
So I was thinking, that it would be easier:
- to load the Background-Image
- overlay picture1
- get an new image out of this two ones
- using this new picture as Background Image
- overlay picture2
- get an new image out of this two ones
- using this new picture as Background Image
- overlay picture3
And so on.
But there is still a memory problem even if I use the garbage function out of the VBBitmap Lib. What I’m doing wrong?
I have a Background Image (Png) which is nearly the size of my Screen.
Now I want to overlay 31 other PNG.
My first try was to create 32 ImageViews all of the same size. This worked for a few pics but than I ran out of memory.
My next try was the same but loading the Image with VBBitmap Lib – this worked but the quality of some pictures is so bad….
So I was thinking, that it would be easier:
- to load the Background-Image
- overlay picture1
- get an new image out of this two ones
- using this new picture as Background Image
- overlay picture2
- get an new image out of this two ones
- using this new picture as Background Image
- overlay picture3
And so on.
But there is still a memory problem even if I use the garbage function out of the VBBitmap Lib. What I’m doing wrong?
B4X:
Sub Globals
Dim Open As ImageView
Dim Bottles As ImageView
Dim bmp As Bitmap
Dim BitmapLib As SmartBitmap
Dim Obj1, Obj2 As Reflector
Dim c As Canvas
Dim F01 As Boolean
Dim F02 As Boolean
Dim F03 As Boolean
Dim F04 As Boolean
Dim F05 As Boolean
Dim F06 As Boolean
Dim F07 As Boolean
Dim F08 As Boolean
Dim F09 As Boolean
Dim F10 As Boolean
Dim F11 As Boolean
Dim F12 As Boolean
Dim F13 As Boolean
Dim F14 As Boolean
Dim F15 As Boolean
Dim F16 As Boolean
Dim F17 As Boolean
Dim F18 As Boolean
Dim F19 As Boolean
Dim F20 As Boolean
Dim F21 As Boolean
Dim F22 As Boolean
Dim F23 As Boolean
Dim F24 As Boolean
Dim F25 As Boolean
Dim F26 As Boolean
Dim F27 As Boolean
Dim F28 As Boolean
Dim F29 As Boolean
Dim F30 As Boolean
Dim F31 As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Layout
Activity.LoadLayout("Layout1")
Bottles.Visible = False
File.Copy(File.DirAssets,"Open.png",File.DirInternal,"Open.png")
File.Copy(File.DirAssets,"01.png",File.DirInternal,"01.png")
File.Copy(File.DirAssets,"02.png",File.DirInternal,"02.png")
File.Copy(File.DirAssets,"03.png",File.DirInternal,"03.png")
File.Copy(File.DirAssets,"04.png",File.DirInternal,"04.png")
File.Copy(File.DirAssets,"05.png",File.DirInternal,"05.png")
File.Copy(File.DirAssets,"06.png",File.DirInternal,"06.png")
File.Copy(File.DirAssets,"07.png",File.DirInternal,"07.png")
File.Copy(File.DirAssets,"08.png",File.DirInternal,"08.png")
File.Copy(File.DirAssets,"09.png",File.DirInternal,"09.png")
File.Copy(File.DirAssets,"10.png",File.DirInternal,"10.png")
File.Copy(File.DirAssets,"11.png",File.DirInternal,"11.png")
File.Copy(File.DirAssets,"12.png",File.DirInternal,"12.png")
File.Copy(File.DirAssets,"13.png",File.DirInternal,"13.png")
File.Copy(File.DirAssets,"14.png",File.DirInternal,"14.png")
File.Copy(File.DirAssets,"15.png",File.DirInternal,"15.png")
File.Copy(File.DirAssets,"16.png",File.DirInternal,"16.png")
File.Copy(File.DirAssets,"17.png",File.DirInternal,"17.png")
File.Copy(File.DirAssets,"18.png",File.DirInternal,"18.png")
File.Copy(File.DirAssets,"19.png",File.DirInternal,"19.png")
File.Copy(File.DirAssets,"20.png",File.DirInternal,"20.png")
File.Copy(File.DirAssets,"21.png",File.DirInternal,"21.png")
File.Copy(File.DirAssets,"22.png",File.DirInternal,"22.png")
File.Copy(File.DirAssets,"23.png",File.DirInternal,"23.png")
File.Copy(File.DirAssets,"24.png",File.DirInternal,"24.png")
File.Copy(File.DirAssets,"25.png",File.DirInternal,"25.png")
File.Copy(File.DirAssets,"26.png",File.DirInternal,"26.png")
File.Copy(File.DirAssets,"27.png",File.DirInternal,"27.png")
File.Copy(File.DirAssets,"28.png",File.DirInternal,"28.png")
File.Copy(File.DirAssets,"29.png",File.DirInternal,"29.png")
File.Copy(File.DirAssets,"30.png",File.DirInternal,"30.png")
File.Copy(File.DirAssets,"31.png",File.DirInternal,"31.png")
Open.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "Open.png", Open.Width , Open.Height)
Open.Visible = True
F01 = True
F02 = True
F03 = True
F04 = True
F05 = True
F06 = True
F07 = True
F08 = True
F09 = True
F10 = True
F11 = True
F12 = True
F13 = True
F14 = True
F15 = True
F16 = True
F17 = True
F18 = True
F19 = True
F20 = True
F21 = True
F22 = True
F23 = True
F24 = True
F25 = True
F26 = True
F27 = True
F28 = True
F29 = True
F30 = True
F31 = True
draw_bottle
End Sub
Sub draw_bottle
Bottles.Visible = True
If F01 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "01.png", Open.Width , Open.Height)
add_bottle
End If
If F02 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "02.png", Open.Width , Open.Height)
add_bottle
End If
If F03 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "03.png", Open.Width , Open.Height)
add_bottle
End If
If F04 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "04.png", Open.Width , Open.Height)
add_bottle
End If
If F05 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "05.png", Open.Width , Open.Height)
add_bottle
End If
If F06 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "06.png", Open.Width , Open.Height)
add_bottle
End If
If F07 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "07.png", Open.Width , Open.Height)
add_bottle
End If
If F08 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "08.png", Open.Width , Open.Height)
add_bottle
End If
If F09 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "09.png", Open.Width , Open.Height)
add_bottle
End If
If F10 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "10.png", Open.Width , Open.Height)
add_bottle
End If
If F11 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "11.png", Open.Width , Open.Height)
add_bottle
End If
If F12 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "12.png", Open.Width , Open.Height)
add_bottle
End If
If F13 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "13.png", Open.Width , Open.Height)
add_bottle
End If
If F14 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "14.png", Open.Width , Open.Height)
add_bottle
End If
If F15 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "15.png", Open.Width , Open.Height)
add_bottle
End If
If F16 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "16.png", Open.Width , Open.Height)
add_bottle
End If
If F17 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "17.png", Open.Width , Open.Height)
add_bottle
End If
If F18 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "18.png", Open.Width , Open.Height)
add_bottle
End If
If F19 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "19.png", Open.Width , Open.Height)
add_bottle
End If
If F20 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "20.png", Open.Width , Open.Height)
add_bottle
End If
If F21 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "21.png", Open.Width , Open.Height)
add_bottle
End If
If F22 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "22.png", Open.Width , Open.Height)
add_bottle
End If
If F23 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "23.png", Open.Width , Open.Height)
add_bottle
End If
If F24 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "24.png", Open.Width , Open.Height)
add_bottle
End If
If F25 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "25.png", Open.Width , Open.Height)
add_bottle
End If
If F26 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "26.png", Open.Width , Open.Height)
add_bottle
End If
If F27 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "27.png", Open.Width , Open.Height)
add_bottle
End If
If F28 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "28.png", Open.Width , Open.Height)
add_bottle
End If
If F29 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "29.png", Open.Width , Open.Height)
add_bottle
End If
If F30 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "30.png", Open.Width , Open.Height)
add_bottle
End If
If F31 = True Then
Bottles.Bitmap = BitmapLib.LoadBitmap(File.DirInternal, "31.png", Open.Width , Open.Height)
add_bottle
End If
Bottles.Visible = False
End Sub
Sub add_bottle
bmp.InitializeMutable(Open.Width, Open.Height)
c.Initialize2(bmp)
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Open.Bitmap = bmp
bmp = Null
Bottles.Bitmap = Null
BitmapLib.Garbage
End Sub