2014-09-22 71 views
0

在我的應用程序中,我希望通過相機拍攝的圖像顯示爲純黑白圖像,因爲我希望打印拍攝的圖像圖像後來..如何將圖像的顏色更改爲android中的黑白圖像

我試了很多代碼轉換成黑白圖像,但仍然圖像來作爲灰度圖像像素以外的黑色應該變成白色。

,我使用下面給出的代碼:

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; 

} 

,我得到的輸出是enter image description here

這不是我想要的,因爲它是略灰的圖像色彩。 。

我想按照如下方式顯示圖像:

enter image description here

我該如何做到這一點?請幫忙 !!!

+0

嘗試此鏈接http://stackoverflow.com/questions/3373860/convert-a-bitmap-to-grayscale-in-android – 2014-09-22 13:23:55

+0

@IllegalArgument該鏈接是指代碼,它產生的灰度圖像已被用於我的代碼。 – shivani 2014-09-22 13:34:00

+0

@IllegalArgument我想成爲像凸輪掃描儀應用程序..因此,圖像看起來像一個掃描文檔 – shivani 2014-09-23 05:00:20

回答