Bitmap & bitmapdrawable...

skipsy

Member
Licensed User
Longtime User
Hello,

The beginner's guide does not explain the difference between a variable
declared as BITMAP and an other one declared as BITMAPDRAWABLE.

Why do we have to do first :
bmpbackground.Initialize( File.DirAssets, "background.jpg" )
and then :
bmdbackground.Initialize( bmpbackground )
to finally write :
activity.Background = bmdbackground

and not :
bmpbackground.Initialize( File.DirAssets, "background.jpg" )
activity.Background = bmpbackground

By the way... Is there any other documentation I could download and read
instead of posting 1000 boring questions : :sign0012:

Thank you,
W.W.
 

klaus

Expert
Licensed User
Longtime User
bmpBackground is a Bitmap object.
bmdBackground is a BitmapDrawable object.

In the program from the Beginner's Guide we need a Bitmap (bmpBackground) to be able to draw onto it with a Canvas. And then set this bitmap to the BitmapDrawable (bmdBackground) and then set this BitmapDrawable to the Activitys Background, thats how Android does work.
If you dont need to draw onto the Background Bitmap you could initialize the BitmapDrawable directly with
B4X:
bmdbackground.Initialize(LoadBitmap(File.DirAssets, "background.jpg"))
The Background property can be of different types: ColorDrawable, GradientDrawable and BitmapDrawable, that's why we need to define the BitmapDrawable.

The different documentation I know of is the: Beginner's Guide, the Dokumentation Wiki, the Tutorials, the HelpViewer, the B4A Help Viewer and the forum. And more generaly Android Developpers.

Best regards.
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
Well, I thought that sleep on it could help... but I am still not sure to
understand.
Does it mean that if I write :
B4X:
Dim bmpbackground as bitmap
.
.
bmpbackground.Initialize( File.DirAssets, "background.jpg" )
activity.Background = bmpbackground
The background wil be displayed but I wont be able to write anything on it ?
(except buttons or using layers, panels... ???)

I am going to do mores tests

Thanks for your help.
William
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Your code doesn't work, it throughs an error!
B4X:
Activity.Background = bmpBackground
This code doesn't work either, throughs also an error!
B4X:
bmdBackground.Initialize(LoadBitmap(File.DirAssets, "Rose1.jpg"))
Activity.Background = bmdBackground
cvsBackground.Initialize2(bmdBackground.Bitmap)
This code does work:
You can draw with the canvas on the background
B4X:
Dim bmpBackground As Bitmap
Dim bmdBackground As BitmapDrawable
Dim cvsBackground As Canvas
.
.
bmpBackground.Initialize(File.DirAssets, "Rose1.jpg")
bmdBackground.Initialize(bmpBackground)
Activity.Background = bmdBackground
cvsBackground.Initialize(Activity)
Best regards.
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
Hello,

This is what I did (even if I did not understood everything at that time).
I had trouble displaying a bitmap over the background because I wrote
B4X:
Dim bmpBackground As Bitmap
Dim bmdBackground As BitmapDrawable
Dim cvsBackground As Canvas
.
.
cvsBackground.Initialize(Activity)   <------------ was not at the right place
bmpBackground.Initialize(File.DirAssets, "Rose1.jpg")
bmdBackground.Initialize(bmpBackground)
Activity.Background = bmdBackground

I still have many things to find out regarding sprites and moves... Exciting
and frustrating when you learn a new language and plateform.
I will probably bother all of you many times :sign0013:
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I still have many things to find out regarding sprites and moves... Exciting
and frustrating when you learn a new language and plateform.
We all are or (were?) in the same case.

I will probably bother all of you many times
Don't worry, that's what this forum is for :).

Best regards.
 
Upvote 0
Top