简体   繁体   中英

how to change the color of an image to black and white in android

In my application i want the image which is captured through the camera to appear as a pure black and white image , as i want the captured image image to be printed later..

I tried many codes to convert the into a black and white image but still the image comes as a gray scale image the pixels other than the black ones should become white.

The code that i am using is given as below :

    public static Bitmap blackNwhite(Bitmap bitmap)
{

    Bitmap bmpMonochrome = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmpMonochrome);
    ColorMatrix ma = new ColorMatrix();
    ma.setSaturation(0);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(ma));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return bmpMonochrome;

}

The image that i get as the output is 在此处输入图片说明

which is not how i wanted as it is slightly greyish is color..

I want the image to be displayed as follows :

在此处输入图片说明

how can i achieve this????? Please help !!!

You can go for following link:

What is the fastest way to convert an image to pure black and white in C#?

Using exact ColorMatrix, best results can be obtained.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM