monochrome black-and-white bitmap

2019-02-28 21:04发布

I'm working on Android for converting a colored bitmap captured from the camera into a black-and-white monochromatic image (no grays!).

I've got several methods for the gray scale conversion but I can't manage to get my image to a b&W format.

Are there any methods for converting a bitmap into this format?

2条回答
小情绪 Triste *
2楼-- · 2019-02-28 21:18

You can try this approatch:

  1. getPixels() from Bitmap instance
  2. iterate through all pixcels and if its code is more than some value to set white color otherwise black color.
  3. setPixels() to Bitmap.
查看更多
The star\"
3楼-- · 2019-02-28 21:26

One solid way is a mean threshold bitmap. The method is described in this paper, in the method section. It's often used for image alignment, and will compensate for different brightness levels, etc. You can use it straight from color, or after a greyscale conversion. After you get your image, you can simply set the white pixels to white, and black to black with setPixels() from a buffer.

You can also tweak it so that it doesn't use the mean exactly. You could have a slider for 0-100% black, where the mean would be 50%. That way you could do on-the-fly adjustments for each individual picture. You just have to recalculate the threshold and apply the pixel buffer again.

查看更多
登录 后发表回答