Which is the best way to load bitmap?

capisx

Member
Licensed User
Longtime User
Hi all,

Can someone tell me which is the best way to load image regarding memory consumption:

1. Load directly to view variable like sample code bellow
B4X:
ImageView1.Bitmap=LoadBitmapSample(File.DirAssets,"image.png",ImageView1.Width,ImageView1.Height)

Button1.SetBackgroundImage(LoadBitmapSample(File.DirAssets,"image.png",Button1.Width,Button1.Height))

--- or ---

2. Load to Bitmap object first then assign it to the view
B4X:
Dim loadbmp as Bitmap
loadbmp.InitializeSample(File.DirAssets,"image.png",loadbmp.Width,loadbmp.height)

ImageView1.Bitmap=loadbmp
Button1.SetBackgroundImage(loadbmp)

Or maybe both use the same amount of memory.

Sorry if this is a stupid question :D. Thanks.
 
Last edited:

Theera

Expert
Licensed User
Longtime User
Hi all,

Can someone tell me which is the best way to load image regarding memory consumption:

1. Load directly to view variable like sample code bellow
B4X:
ImageView1.Bitmap=LoadBitmapSample(File.DirAssets,"image.png",ImageView1.Width,ImageView1.Height)

Button1.SetBackgroundImage(LoadBitmapSample(File.DirAssets,"image.png",Button1.Width,Button1.Height))

--- or ---

2. Load to Bitmap object first then assign it to the view
B4X:
Dim loadbmp as Bitmap
loadbmp.InitializeSample(File.DirAssets,"image.png",loadbmp.Width,loadbmp.height)

ImageView1.Bitmap=loadbmp
Button1.SetBackgroundImage(loadbmp)

Or maybe both use the same amount of memory.

Sorry if this is a stupid question :D. Thanks.

Hi capisx,

You could do both,but you should load bmp file from File.DirAssets only once by use if FirstTime Then...End If
 
Upvote 0
Top