iOS Question GetDrawable in B4i

luke2012

Well-Known Member
Licensed User
Longtime User
Hi All,
within my B4A App I generate all drawable images (hdpi, xdpi etc) and then I set te image with:

B4X:
img.Background = xml.GetDrawable("img_name")

How I can port this to B4i ?

Thanks in advance for your reply :)
 

Misterbates

Active Member
Licensed User
Please first read the beginners guide for B4i - section 5.3 is about icon sizes but *also* about images! https://www.b4x.com/b4i/files/guide.zip

In summary:
* You still provide multiple images but they are stored in the Files folder and are named "img_name", "img_name@2x", "img_name@3x"
* You load an image using LoadBitmap(File.DirAssets, "img_name") or LoadBitmapResize() - the appropriate resolution image is loaded as a bitmap object
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
Please first read the beginners guide for B4i - section 5.3 is about icon sizes but *also* about images! https://www.b4x.com/b4i/files/guide.zip

In summary:
* You still provide multiple images but they are stored in the Files folder and are named "img_name", "img_name@2x", "img_name@3x"
* You load an image using LoadBitmap(File.DirAssets, "img_name") or LoadBitmapResize() - the appropriate resolution image is loaded as a bitmap object

*** B4i GUIDE
You should provide different icon files for the different screen scales.
File names for the different scales.  myicon.png generic name  [email protected] file name for scale 2 images.  [email protected] file name for scale 3 images.
In an Initialize method you must use the generic file name. iOS selects automatically the correct file according to the device scale.
Example for a TabBar item. You must use only btnCH0.png and not [email protected] nor [email protected].
*** B4i GUIDE

B4X:
'Define a button with custom bitmaps 
Dim tbi As TabBarItem  ' define a new TabBarItem 
'define a custom TabBarItem with custom icons
tbi.Initialize("Countries", LoadBitmap(File.DirAssets, "btnCH0.png"), LoadBitmap(File.DirAssets, "btnCH1.png"))

it's quite clear for me.
So I can pick the "img_name", "img_name@2x", "img_name@3x" with the "Add Files" button of the Files manager tab instead of manually copying the images files (within a custom dir) like B4A (Object / res / drawable) ?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
So I can pick the "img_name", "img_name@2x", "img_name@3x" with the "Add Files" button of the Files manager tab instead of manually copying the images files (within a custom dir) like B4A (Object / res / drawable) ?
Yes.
 
Upvote 0
Top