Android Question Single icon/bitmap file

acorrias

Member
Licensed User
Longtime User
Hi all
I am going to design an app with different icons. Is there a way to provide a single file containing the whole set of icon and to select them in order to assign to a panel?
that is, instead of these three assignements , three files to load to the project, as following
marker.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "marker2.png", marker.Width, marker.Width))
panel2.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "marker3.png", marker.Width, marker.Width))
panel4.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "sky.png", marker.Width, marker.Width))

to have the equivalent of SetBackgroundImage but with the rectangular cut to get the image.

thanks in advance
Alex
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can use a canvas to extract parts of an image, here is a code fragment (not tested) and I don't know if that is the best and right way
B4X:
    Dim canvas1 As Canvas 'you need to asign the canvas to a panel, which is not done is this code
    Dim DestRect1 As Rect
    Dim SrcRect1 As Rect
    Dim bitmap1 As Bitmap 'will be your original bitmap        
    Dim bitmap2 As Bitmap  

    bitmap1.Initialize(File.DirAssets, "myicons.jpg")

    DestRect1.Initialize( 0, 0, 100dip,100dip1 )
    SrcRect1.Initialize(0,0,bitmap1.Width,bitmap1.Height)
    canvas1.DrawBitmap(  bitmap1, SrcRect1, DestRect1) 'draws the bitmap to the destination clip rectangle.
    bitmap2 = canvas1.Bitmap
    'then go on with bitmap2 and draw it on a imageview
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…