java修改图片像素的颜色出现锯齿
int[] rgb = new int[3];
BufferedImage bi = (BufferedImage) ImageIO.read(new File("d:/24.png"));
// 获取图像的宽度和高度
int width = bi.getWidth();
int height = bi.getHeight();
boolean isTransparent = true;
// 扫描图片
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {// 行扫描
int dip = bi.getRGB(j, i);
rgb[0] = (dip & 0xff0000) >> 16;
rgb[1] = (dip & 0xff00) >> 8;
rgb[2] = (dip & 0xff);
System.out.println("dip:"+dip+" "+rgb[0]+" "+rgb[1]+" "+rgb[2]+" "+convertRGBToHex(rgb[0],rgb[1],rgb[2]));
if(rgb[0]==26&&rgb[1]==216&&rgb[2]==0){
bi.setRGB(j, i, -65281);
}
}
if(i==50)break;
}
BufferedImage target = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics2D g2d = (Graphics2D)target.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawImage(bi.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
g2d.dispose();
ImageIO.write(target, "png", new File("d:/24_2.png"));
用图片修改图片里固定像素的颜色,如把图片里的绿色改成粉丝。然后创建一张新的图片,这时候新的图片就会出现锯齿。有朋友知道如何去解决吗? 代码了用了Graphics2D 的方式去去除图片的锯齿但是还是没效果
kruly
9 years, 5 months ago