【问题标题】:how to change the color of an image to black and white in android如何在android中将图像的颜色更改为黑白
【发布时间】:2015-08-18 23:05:42
【问题描述】:

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

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

我使用的代码如下:

    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;

}

我得到的输出图像是

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

我希望图像显示如下:

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

【问题讨论】:

  • @IllegalArgument 该链接指的是产生灰度图像的代码,该图像已在我的代码中使用。
  • @IllegalArgument 我想成为 Cam 扫描仪应用程序.. 让图像看起来像扫描文档

标签: android image bitmap monochrome


【解决方案1】:

你可以去以下链接:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多