B4J Question Determine if an image has transparent pixels

hanyelmehy

Active Member
Licensed User
Longtime User
how to Determine if an image has transparent pixels ( Alpha channel)
and how to remove it from image
 

hanyelmehy

Active Member
Licensed User
Longtime User
What are you trying to do? If you want to show an image and replace the transparent regions with a solid color, then it will be simpler to put it in a panel with the relevant color.
i just want to check if image have alpha channel and remove it if found (like image utility)
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
Check this code: https://www.b4x.com/android/forum/threads/get-image-pixels.91666/

Just loop over all pixels, check the alpha channel. Don't know how fast this will be.
i already use this code
B4X:
Dim CheckBmb As B4XBitmap = XUI.LoadBitmap(File.GetFileParent(imgfile),File.GetName(imgfile))
    Dim bc1 As BitmapCreator
    bc1.Initialize(CheckBmb.Width,CheckBmb.Height)
    bc1.CopyPixelsFromBitmap(CheckBmb)
    Dim IsTrans As Boolean=False
    For x = 0 To bc1.mWidth - 1
        For y = 0 To bc1.mHeight - 1
            If bc1.IsTransparent(x,y) Then
                IsTrans=True
                Exit
            End If
        Next
    Next
    Log("Trans :" & IsTrans)
but i did not if this equal to java function hasAlpha() or not
also i use B4XCanvas to create new image with color background and save it as png ,but result image still have alpha channel
 
Upvote 0
Top