Wish Effect black and white in B4XBitmapEffects

angel_

Well-Known Member
Licensed User
Longtime User
I would like black and white (without grayscale) to be added to B4XBitmapEffects
 

klaus

Expert
Licensed User
Longtime User
It is not really an answer to your request but you could do it.

You might have a look at the BitmapCreatorDemo1 project in the B4X Graphics booklet.
It contains a class with several effects, including Black and White.



This is the code:

B4X:
'calculates the mean scale value to generate a mean scaled image
Public Sub BlackAndWhite (Image As B4XBitmap, Threshold As Int) As B4XBitmap
    Private x, y, Mean, BWCol As Int
    Private col0, col1 As ARGBColor
    Private bmcImage, bmcResult As BitmapCreator
   
    bmcImage.Initialize(Image.Width, Image.Height)
    bmcImage.CopyPixelsFromBitmap(Image)
    bmcResult.Initialize(Image.Width, Image.Height)
   
    For y = 0 To Image.Height -1
        For x = 0 To Image.Width -1
            bmcImage.GetARGB(x, y, col0)
            col1.a = col0.a
            Mean = (col0.r + col0.g + col0.b) / 3
            If Mean >= Threshold Then
                BWCol = 255
            Else
                BWCol = 0
            End If          
            col1.r = BWCol
            col1.g = BWCol
            col1.b = BWCol
            bmcResult.SetARGB(x, y, col1)
        Next
    Next
    Return bmcResult.Bitmap
End Sub

It calculates the mean value of the three colors for each pixel and set black or white with a threshold value and returns a B4XBitmap.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…