import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Image {

	public static void main(String[] args) {
		try {
			// Read in the image
			BufferedImage image = ImageIO.read(new File("bmw-inside.png"));
			
			// Get height and width
			int height = image.getHeight();
			int width = image.getWidth();
			System.out.println(width + " x " + height);
			
			// Get the integer pixel value at a position
			int pixel = image.getRGB(120, 53);
			// Create a color using the integer pixel to extract R, G, B and alpha value
			Color c = new Color(pixel);
			System.out.println(c.getRed() + ", " + c.getGreen() + ", " + c.getBlue() + ", " + c.getAlpha());
			
			// Create a new color - white			
			c = new Color(255,255,255);
			// Get its integer pixel value
			int new_pixel = c.getRGB();		
			
			// Change the pixel color to the new color (white) in a small patch
			for (int x=15; x<width-20; x++) {
				for (int y=30; y<40; y++) 
					image.setRGB(x, y, new_pixel);
			}
			
			// Save the new image in an external file
			ImageIO.write(image, "png", new File("new_car.png"));
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
