Android Question b4a set transparent png image

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I have a ColorDrawable label with a background color set at runtime by setting:

B4X:
TempLbl As Label
TempLbl.Color = xui.Color_RGB(246,135,46)

then I try to load a transparent png with:

TempLbl.SetBackgroundImage(LoadBitmap(File.DirAssets,"dog.png")):
TempLbl.SetBackgroundImage(LoadBitmap(File.DirAssets,"dog.png"))

and I would expect the background color to be kept but that does not happen..what am I missing?

thanks
 

PaulMeuris

Active Member
Licensed User
Or add the label to an orange panel...
And after reading your response... you might have a look at my chess game...
 
Last edited:
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
because the labels are 64 (they represent a chess board) and in the B4j version I do that nicely using CSSUtils..below what I do in B4j.

B4X:
Sub ClearBoard
    Dim ii As Int
    For ii = 0 To 63
       Squares(ii).Style=IIf(SqColor(ii)=0,EmptyW,EmptyB)
    Next   
End Sub

' Squares() is a 64 labels array and EmptyW and EmptyB are initialized as
'EmptyW = Squares(1).Style
'EmptyB  = Squares(0).Style
' basically in this way I set the colors of all the square'
' the below sub sets the pieces in the labels looking at the piece in the square
' which is the CurrentPos.Pieces() array, positive pieces are white, neg are black'
Sub PrintBoard
    Dim ii,TempPiece As Int
    For ii = 0 To 63
        TempPiece = CurrentPos.Pieces(ii)
        Select Abs(TempPiece)
           Case 0
              Squares(ii).Style=IIf(SqColor(ii)=0,EmptyW,EmptyB)       
           Case 1
                 If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WK.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BK.png")
              End If
           Case 2
              If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WQ.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BQ.png")
              End If     
           Case 3       
              If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WR.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BR.png")
              End If
           Case 4
              If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WB.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BB.png")
              End If   
           Case 5
                 If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WN.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BN.png")
              End If
           Case 6
                 If TempPiece > 0 Then
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"WP.png")   
              Else     
                 CSSUtils.SetBackgroundImage(Squares(ii),File.DirAssets,"BP.png")
              End If 
                  
        End Select
        
    Next
    
        
End Sub

basically I would like to replicate this in B4A..
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
ok at then end I followed @aeric suggestions and added 64 transparent imageviews and can set the bitmap of the imageview to the image I need or to null if I want to "emtpy" the square..I don't like it too much but it works. In my mind portability within B4X environment is fundamental and when I find something apparently so simple as labelview that cannot be ported I get frustrated..anyway..
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Did you tried with CSBuilder?
 

Attachments

  • Label_Image.zip
    28.8 KB · Views: 43
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
ok at then end I followed @aeric suggestions and added 64 transparent imageviews and can set the bitmap of the imageview to the image I need or to null if I want to "emtpy" the square..I don't like it too much but it works. In my mind portability within B4X environment is fundamental and when I find something apparently so simple as labelview that cannot be ported I get frustrated..anyway..
Use the cross platform API and controls if you want a cross platform features. You should never see "label" in your code. Change it to B4XView.

JavaFX CSS feature is very very platform specific.
 
Upvote 0
Top