Android Question Why are transparent png images not working?

jkhazraji

Active Member
Licensed User
Longtime User
My code:
B4X:
         Dim img As ImageView
    Dim MyImage As Bitmap
    img.Initialize("")
    MyImage.Initialize(File.DirAssets,"clockglass.png")
    img.Bitmap=MyImage
    Activity.AddView(10dip,10dip,100dip,100dip)
The image file, which been transparent by Photoshop, is available..
 

Attachments

  • clockglass.png
    clockglass.png
    61.6 KB · Views: 269

jkhazraji

Active Member
Licensed User
Longtime User
Not working.. deleted 'img' was a typo.. The original code is as you mentioned. Still not working.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It works OK for me. The image is correct.

In order to discard that nothing else is happening, you should confirm that your code works ok with a non-transparent image?

Possible causes
Sometimes it is needed to call --> Activity.invalidate
Something else is being drawn onto it just after drawing
Your code is not being called...
....
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Thanks for your replies..but when I ran the code only the ImageView is shown empty without an image
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
     Dim img As ImageView
     Dim lbl As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Draw_ClockGlass
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Draw_ClockGlass()
    lbl.Initialize("")
    Activity.AddView(lbl,0,0,100dip,100dip)
    Dim Bitmap1 As Bitmap
    img.Initialize("imgv")
    Bitmap1.Initialize(File.DirAssets,"clockglass.png")
    img.Bitmap=Bitmap1
   Activity.AddView(img,0,0,200dip ,200dip)
    Activity.Invalidate
   
End Sub
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I cannot see anything strange, see attached screenshot

Perhaps your "clockglass.png" version in Files folder is not the one that you have attached to the first post?

Which android version are you running?
 

Attachments

  • sc.png
    sc.png
    35.8 KB · Views: 297
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
My Android version is 24 and I am using the same file (clockgalss.png) which I have uploaded previously. I got this screen :(
 

Attachments

  • sshot.png
    sshot.png
    56.9 KB · Views: 248
Upvote 0

sorex

Expert
Licensed User
Longtime User
try

B4X:
img.gravity=gravity.fill

the roundings of that circle are probably beyond what you see (outside of that square)
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Thanks...I just came out with the same answer like yours by searching the forum. That solved the problem
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
see .fill as resize to fit in the dimensions of your image. what you now had was that it took the original image size and centered it in your image.
that's why you got the square.
 
Upvote 0
Top