I use this @klaus code with @Erel grayscale (B4XBitmapEffects), in B4A it looks pretty good but in B4i the definition is not very good, Any ideas to improve it?
Klaus code:
Klaus code:
[B4X] Documentation Booklets
The B4X documentation booklets are available in PDF format, Download Link. All files are included in the zip file in the link above, pdf booklets and all the source code. You can also download all the source code for al booklets, SourceCode. These booklets cover the four B4X platforms. Some...
www.b4x.com
B4X:
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)
Mean = (col0.r + col0.g + col0.b) / 3
If Mean > Threshold Then
BWCol = 255
Else If Mean > 0.75 * Threshold Then
BWCol = col0.r * 0.21 + col0.g * 0.72 + 0.07 * col0.b
Else
BWCol = 0
End If
col1.r = BWCol
col1.g = BWCol
col1.b = BWCol
col1.a = 255
bmcResult.SetARGB(x, y, col1)
Next
Next
Return bmcResult.Bitmap
End Sub