如何在java中删除图像中的白色像素 [英] How to Delete the white pixels in an image in java
本文介绍了如何在java中删除图像中的白色像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在将图像加载到面板中之前删除图像的白色像素
面板中加载图像的方法是:
How can I remove the white pixels of an image before loading it in the Panel
the method for loading image in panel is:
public void ajouterImage(File fichierImage) {
// desiiner une image à l'ecran
try {
monImage = ImageIO.read(fichierImage);
} catch (IOException e) {
e.printStackTrace();
}
repaint();
}
推荐答案
你无法删除像素来自图像,但你确定可以改变它的颜色,甚至让它变得透明。
You can't remove a pixel for say from an image, but you sure can change the color of it, or even make it transparent.
假设你有一个像素数组作为某个变量,你可以给它 BufferedImage
的RGB值。像素数组将被称为像素
:
Let's say you have a pixel array as a variable somewhere, and you can give it the RGB value of your BufferedImage
. The pixel array will be called 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中删除图像中的白色像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文