java - 如何用java删除图像中的白色像素

标签 java

如何在将图像加载到面板之前删除图像的白色像素
在面板中加载图像的方法是:

public  void ajouterImage(File fichierImage) {   
    // desiiner une image à l'ecran 
    try {
        monImage = ImageIO.read(fichierImage);
    } catch (IOException e) {
        e.printStackTrace();
    }
    repaint(); 
}  

最佳答案

您无法从图像中删除像素,但您确实可以更改它的颜色,甚至使其透明。

假设您在某处有一个像素数组作为变量,您可以为其指定 BufferedImage 的 RGB 值。像素数组将被称为pixels:

try {
    monImage = ImageIO.read(fichierImage);
    int width = monImage.getWidth();
    int height = monImage.getHeight();
    pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);

    for (int i = 0; i < pixels.length; i++) {
        // I used capital F's to indicate that it's the alpha value.
        if (pixels[i] == 0xFFffffff) {
            // We'll set the alpha value to 0 for to make it fully transparent.
            pixels[i] = 0x00ffffff;
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}

关于java - 如何用java删除图像中的白色像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23980554/

相关文章:

java - 最喜欢的开源 Google App Engine 应用(Java 或 Python)

java - 将 LineChart(javafx) 样式设置为子元素

java - Weblogic启动异常

java - 如何将泛型与spring data jpa的JpaRepository一起使用

java - Mysql数据截断: Data truncation: Out of range value for column 'column' at row 1

java - 如何使用工厂模式来获取数据库客户端的实例?

java - JNR 的回调/闭包采用指针参数

java - JSON 到 Java 中的对象?

java - 如何让 ExampleMatcher 只匹配一个属性?

java - Hibernate JSF MySql,丢失数据库连接