Monochrome image needed

holographl

Member
Licensed User
Longtime User
I know this is not normal anymore but I need to be able to take a greyscale image and make it black and white only. I tried using the RSImage library but I cant seem to see how to adjust the threshold.

Does anyone have any ideas for how to do this or how to adjust the threshold. I would like to allow the user to adjust the threshold as the images are not consistent.

thanks,
 

thedesolatesoul

Expert
Licensed User
Longtime User
B4X:
Dim Threshold as Int
Dim TotalSum as Long
Dim b as Bitmap

For i = 0 to b.Width-1
     For j = 0 to b.Height-1
           If b.GetPixel(i,j) > Threshold then 
              b.SetPixel(i,j) = Colors.White
            Else
              b.SetPixel(i,j) = Colors.Black
            End If
            TotalSum = TotalSum + b.GetPixel(i,j)
      Next
Next

Dim AvgThreshold as Int
AvgThreshold = TotalSum/ (b.Width * b.Height)

EDIT: Note SetPixel does not exist...please see below for using the BitmapExtended lib.
 
Last edited:
Upvote 0

holographl

Member
Licensed User
Longtime User
One small problem

I had something like that but each time I try to use it B4A says that bitmap.SetPixel does not exist.

Is it possible this was added in a later version?

I have version 2.20 at this time.
 
Upvote 0

holographl

Member
Licensed User
Longtime User
Something wierd

I copied the code that Desolatesoul provided and ran the compiler.
I get this error message.

Compiling code. Error
Error compiling program.
Error description: Unknown member: setpixel
Occurred on line: 55
b.SetPixel(i,j) = Colors.White
Word: setpixel

I have tried many other bitmaps in other programs and none of them even show setpixel in the list of methods that pops up when you are typing.

Do I have a bad install or something?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I had to use something simular a few days ago and also had the getPixel only.

There is a bitmap.drawPoint method tho which does the same thing.

Edit: drawpoint is for use with the canvas
 
Last edited:
Upvote 0

holographl

Member
Licensed User
Longtime User
Figured it out

I got it to work using the BitmapExtended library.

I guess the only issue is whether SetPixel is supposed to be showing up in Bitmap or not? If so there is something strange going on.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Maybe the code is there but is the reference to it missing.

I guess Erel only knows the answer to that one :)
 
Upvote 0
Top