当前位置:操作系统 > 安卓/Android >>

Android 图片转灰度

[java]  
/** 
 * 图片转灰度 
 *  
 * @param bmSrc 
 * @return 
 */  
public static Bitmap bitmap2Gray(Bitmap bmSrc)  
{  
    int width, height;  
    height = bmSrc.getHeight();  
    width = bmSrc.getWidth();  
    Bitmap bmpGray = null;  
    bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);  
    Canvas c = new Canvas(bmpGray);  
    Paint paint = new Paint();  
    ColorMatrix cm = new ColorMatrix();  
    cm.setSaturation(0);  
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);  
    paint.setColorFilter(f);  
    c.drawBitmap(bmSrc, 0, 0, paint);  
  
    return bmpGray;  
}  
 
/**
* 图片转灰度
* @param bmSrc
* @return
*/
public static Bitmap bitmap2Gray(Bitmap bmSrc)
{
int width, height;
height = bmSrc.getHeight();
width = bmSrc.getWidth();
Bitmap bmpGray = null;
bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas c = new Canvas(bmpGray);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmSrc, 0, 0, paint);
 
return bmpGray;
}
效果图:
 
 
 
\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,