gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:47:51 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com