JavaBufferedImage가 있습니다. 전경은 검은 색이고 배경은 투명합니다. 이미지를 빨간색으로 다시 채색하고 싶습니다.Java 버퍼 된 이미지의 색을 변경하는 방법
다른 사람의 게시물을 읽었으며이 코드를 사용해 보았습니다. 그러나 이미지를 실행할 때 이미지가 완전히 투명 해집니다.
누구에게 아이디어가 있습니까? Java 2D 이미지 처리 라이브러리가 처음입니다. 감사.
imageIcon= new ImageIcon(getImageURL("/ImagesGun/GunBase.png"));
gunBaseImage= Utilities.toBufferedImage(imageIcon.getImage());
int red = 0x00ff0000;
int green = 0x0000ff00;
int blue = 0x000000ff;
int width = gunBaseImage.getWidth();
int height = gunBaseImage.getHeight();
//Loop through the image and set the color to red
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
long pixel = gunBaseImage.getRGB(x, y);
if(pixel != 0){
red = 0x00ff0000;
gunBaseImage.setRGB(x,y,red);
}
}
}
각 픽셀에 대해 getRGB 및 setRGB를 호출하면 속도가 느려지는데, 그 이유는이 메서드가 풀 컬러 공간 변환을 수행하려고하기 때문입니다. 이미지 처리를 위해서, BufferedImage의 배후에있는 int 배열에 액세스하는 편이 낫습니다. – lbalazscs