public static BufferedImage cutoutByChannel(Object srcIm, int channel) {
    """
	根据指定通道的亮度值（灰度值）来自动计算哪些像素需要扣掉。
	
	@param srcIm
	源图片
	@param channel
	通道编号，0:red 1:green 2:blue 其他:亮度
	@return 抠图后图片对象
    """
        BufferedImage srcImage = read(srcIm);
        BufferedImage resultImage = new BufferedImage(srcImage.getWidth(),
                                                      srcImage.getHeight(),
                                                      BufferedImage.TYPE_4BYTE_ABGR);
        // 开始绘制
        for (int i = 0; i < srcImage.getWidth(); i++) {
            for (int j = 0; j < srcImage.getHeight(); j++) {
                int pixel = srcImage.getRGB(i, j);
                int alpha = 0;
                switch (channel) {
                case CHANNEL_RED:
                    alpha = Colors.getRGB(pixel)[0];
                    break;
                case CHANNEL_GREEN:
                    alpha = Colors.getRGB(pixel)[1];
                    break;
                case CHANNEL_BLUE:
                    alpha = Colors.getRGB(pixel)[2];
                    break;
                default:
                    alpha = Colors.getLuminance(srcImage, i, j);
                    break;
                }
                pixel = (alpha << 24) & 0xff000000 | (pixel & 0x00ffffff);
                resultImage.setRGB(i, j, pixel);
            }
        }

        return resultImage;
    }
public static BufferedImage cutoutByChannel(Object srcIm, int channel) {
        BufferedImage srcImage = read(srcIm);
        BufferedImage resultImage = new BufferedImage(srcImage.getWidth(),
                                                      srcImage.getHeight(),
                                                      BufferedImage.TYPE_4BYTE_ABGR);
        // 开始绘制
        for (int i = 0; i < srcImage.getWidth(); i++) {
            for (int j = 0; j < srcImage.getHeight(); j++) {
                int pixel = srcImage.getRGB(i, j);
                int alpha = 0;
                switch (channel) {
                case CHANNEL_RED:
                    alpha = Colors.getRGB(pixel)[0];
                    break;
                case CHANNEL_GREEN:
                    alpha = Colors.getRGB(pixel)[1];
                    break;
                case CHANNEL_BLUE:
                    alpha = Colors.getRGB(pixel)[2];
                    break;
                default:
                    alpha = Colors.getLuminance(srcImage, i, j);
                    break;
                }
                pixel = (alpha << 24) & 0xff000000 | (pixel & 0x00ffffff);
                resultImage.setRGB(i, j, pixel);
            }
        }

        return resultImage;
    }
public static BufferedImage cutoutByChannel ( Object srcIm , int channel ) { BufferedImage srcImage = read ( srcIm ) ; BufferedImage resultImage = new BufferedImage ( srcImage . getWidth ( ) , srcImage . getHeight ( ) , BufferedImage . TYPE_4BYTE_ABGR ) ; // 开始绘制 for ( int i = 0 ; i < srcImage . getWidth ( ) ; i ++ ) { for ( int j = 0 ; j < srcImage . getHeight ( ) ; j ++ ) { int pixel = srcImage . getRGB ( i , j ) ; int alpha = 0 ; switch ( channel ) { case CHANNEL_RED : alpha = Colors . getRGB ( pixel ) [ 0 ] ; break ; case CHANNEL_GREEN : alpha = Colors . getRGB ( pixel ) [ 1 ] ; break ; case CHANNEL_BLUE : alpha = Colors . getRGB ( pixel ) [ 2 ] ; break ; default : alpha = Colors . getLuminance ( srcImage , i , j ) ; break ; } pixel = ( alpha << 24 ) & 0xff000000 | ( pixel & 0x00ffffff ) ; resultImage . setRGB ( i , j , pixel ) ; } } return resultImage ; }
根据指定通道的亮度值（灰度值）来自动计算哪些像素需要扣掉。

@param srcIm
源图片
@param channel
通道编号，0:red 1:green 2:blue 其他:亮度
@return 抠图后图片对象
根据指定通道的亮度值（灰度值）来自动计算哪些像素需要扣掉。