Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中将图像颜色更改为黑白_Android_Image_Bitmap_Monochrome - Fatal编程技术网

如何在android中将图像颜色更改为黑白

如何在android中将图像颜色更改为黑白,android,image,bitmap,monochrome,Android,Image,Bitmap,Monochrome,在我的应用程序中,我希望通过相机捕获的图像显示为纯黑白图像,因为我希望稍后打印捕获的图像 我尝试了许多代码将图像转换为黑白图像,但图像仍然是灰度图像,除黑色像素外的其他像素应变为白色 我使用的代码如下所示: public static Bitmap blackNwhite(Bitmap bitmap) { Bitmap bmpMonochrome = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitma

在我的应用程序中,我希望通过相机捕获的图像显示为纯黑白图像,因为我希望稍后打印捕获的图像

我尝试了许多代码将图像转换为黑白图像,但图像仍然是灰度图像,除黑色像素外的其他像素应变为白色

我使用的代码如下所示:

    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;

}
我作为输出得到的图像是

这不是我想要的,因为它的颜色有点灰

我希望图像显示如下:


我怎样才能做到这一点?????请帮忙

您可以转到以下链接:


使用精确的ColorMatrix,可以获得最佳结果。

尝试此链接@IllegalArgument此链接指的是生成灰度图像的代码,该图像已在我的代码中使用。@IllegalArgument我希望像Cam scanner app.那样,使图像看起来像扫描过的文档