그림 투명 화 (순 전 히 전재)
2331 단어 Java
package utils;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class TestMainPNG{
public static void main(String[] args) throws Exception{
BufferedImage image = ImageIO.read(new File("C:/Users/grand/Desktop/lanzhou.jpg"));
//
int height = image.getHeight();
int width = image.getWidth();
//
ImageIcon imageIcon = new ImageIcon(image);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics(); //
g2D.drawImage(imageIcon.getImage(), 0, 0, null); // Image
int alpha = 0; //
// Y
for (int y = bufferedImage.getMinY(); y < bufferedImage.getHeight(); y++) {
// X
for (int x = bufferedImage.getMinX(); x < bufferedImage.getWidth(); x++) {
int rgb = bufferedImage.getRGB(x, y);
//
if (colorInRange(rgb)){
alpha = 0;
}else{
//
alpha = 255;
}
// #AARRGGBB
rgb = (alpha << 24) | (rgb & 0x00ffffff);
bufferedImage.setRGB(x, y, rgb);
}
}
// RGB
g2D.drawImage(bufferedImage, 0, 0, null);
// PNG
ImageIO.write(bufferedImage, "png", new File("C:/Users/grand/Desktop/lanzhou.png"));
MyLogger.logger.info(" ");
}
//
public static boolean colorInRange(int color) {
int red = (color & 0xff0000) >> 16;// color(RGB) R
int green = (color & 0x00ff00) >> 8;// color(RGB) G
int blue = (color & 0x0000ff);// color(RGB) B
// RGB
if (red >= color_range && green >= color_range && blue >= color_range){
return true;
};
return false;
}
// 0~255
public static int color_range = 210;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.