如何在Java中将图像转换为棕褐色?

3
我正在寻找一个免费或付费的库。
更新
看起来没有这样的库,但以下代码可以正常工作:
/**
*
* @param img Image to modify
* @param sepiaIntensity From 0-255, 30 produces nice results
* @throws Exception
*/
public static void applySepiaFilter(BufferedImage img, int sepiaIntensity) {
    // Play around with this. 20 works well and was recommended
    // by another developer. 0 produces black/white image
    int sepiaDepth = 20;

    int w = img.getWidth();
    int h = img.getHeight();

    WritableRaster raster = img.getRaster();

    // We need 3 integers (for R,G,B color values) per pixel.
    int[] pixels = new int[w*h*3];
    raster.getPixels(0, 0, w, h, pixels);

    // Process 3 ints at a time for each pixel.
    // Each pixel has 3 RGB colors in array
    for (int i=0;i<pixels.length; i+=3) {
        int r = pixels[i];
        int g = pixels[i+1];
        int b = pixels[i+2];

        int gry = (r + g + b) / 3;
        r = g = b = gry;
        r = r + (sepiaDepth * 2);
        g = g + sepiaDepth;

        if (r>255) r=255;
        if (g>255) g=255;
        if (b>255) b=255;

        // Darken blue color to increase sepia effect
        b-= sepiaIntensity;

        // normalize if out of bounds
        if (b<0) b=0;
        if (b>255) b=255;

        pixels[i] = r;
        pixels[i+1]= g;
        pixels[i+2] = b;
    }
    raster.setPixels(0, 0, w, h, pixels);
}

嘿,干得好!有关于棕褐色滤镜的背景信息吗?我只找到了一些实现。我想了解一些理论方面的知识。 - 501 - not implemented
2个回答

4

第二个链接目前指向恶意软件/钓鱼网站。请尝试使用http://stackoverflow.com/questions/21899824/java-convert-a-greyscale-and-sepia-version-of-an-image-with-bufferedimage代替。 - mwoodman

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接