Android Question Monochrome Bitmap

Fusseldieb

Active Member
Licensed User
Longtime User
Hi,
I need to obtain a monochrome bitmap, but I only found that method: https://www.b4x.com/android/forum/threads/monochrome-image-needed.23412/
THis has two downsides... First, the cod will not compile, I don't know why. I tried adapting it and yet it doesn't compile. Second, I understand what the code does and he analizes every single pixel and writes it to a new bitmap. BUT I believe that this method is slow, is there not a better method? If not, can anyone teach me what I am doing wrong with that code?

Thanks
 

klaus

Expert
Licensed User
Longtime User
First, the cod will not compile...
If you get an error you must tell us what error you get !
Unfortunately you don't give enough information.
... can anyone teach me what I am doing wrong with that code?
Without seeing your code how do you expect we could help ?
The code you are refering to returns a black and white picture only black and white pixels.
If I understand, you want a monochrome picture gray scaled pixels ?
 
Last edited:
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
Thanks for the response klaus.

I have tried it a looong time now, and finally made it.
For everyone searching for this too, here:

B4X:
Dim Threshold As Int=Colors.RGB(200,200,200) 'Here you define the tolerance of B&W
Dim b As Bitmap
b.Initialize(YOUR COLORED IMAGE)

Dim Panel1 as Panel
Dim Canvas1 as Canvas
Panel1.Initialize("Panel1")
Activity.AddView(Panel1,0,0,b.Width,b.Height) 'The Panel MUST be the same size as your bitmap
Canvas1.Initialize(Panel1)

For i = 0 To b.Width-1
     For j = 0 To b.Height-1
           If b.GetPixel(i,j) > Threshold Then
             Canvas1.DrawPoint(i,j, Colors.White)
            Else
             Canvas1.DrawPoint(i,j, Colors.Black)
            End If
      Next
Next

'In Canvas1.Bitmap your B&W Image is stored now :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am afraid that this routine will be slow.
Why don't you use the getPixels function discussed in this thread GetPixel() too slow?
Do you want a monochrome picture with gray scaled pixels or an image with only black and white pixels ?
 
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
Thanks for replying klaus.

I am afraid that this routine will be slow.
Why don't you use the getPixels function discussed in this thread GetPixel() too slow?
This is the same method. GetPixel and SetPixel are same velocity as GetPixel and DrawPoint.

Do you want a monochrome picture with gray scaled pixels or an image with only black and white pixels ?
Only black and white.

PS: I already mentioned that this method would not be the fastest. :D
 
Upvote 0
Top