Answers for "java change image color"

0

java change image color

import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
// w w w  . jav  a 2s  . com
import javax.imageio.ImageIO;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedImage img = colorImage(ImageIO.read(new File("NWvnS.png")));
    ImageIO.write(img, "png", new File("Test.png"));
  }

  private static BufferedImage colorImage(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    WritableRaster raster = image.getRaster();

    for (int xx = 0; xx < width; xx++) {
      for (int yy = 0; yy < height; yy++) {
        int[] pixels = raster.getPixel(xx, yy, (int[]) null);
        pixels[0] = 0;
        pixels[1] = 255;
        pixels[2] = 255;
        raster.setPixel(xx, yy, pixels);
      }
    }
    return image;
  }
}
Posted by: Guest on August-28-2020

Code answers related to "java change image color"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language