// EditImages.java // To run this, first save the image sampleImage.jpg to the current directory import java.awt.*; import java.awt.image.*; import javax.imageio.*; import java.io.*; import javax.swing.*; class MyGraphics { public static void main(String[] args) { // To run this, first save the image sampleImage.jpg to the current directory BufferedImage image = loadBufferedImage("sampleImage.jpg"); Dimension dim = getImageSize(image, 1, 0); int imageWidth = dim.width; int imageHeight = dim.height; // Change all "nearly-black" pixels to blue! for (int x=0; x> 24) & 0xff; int red = (rgba >> 16) & 0xff; int green = (rgba >> 8) & 0xff; int blue = (rgba ) & 0xff; if ((red < 30) && (green < 30) && (blue < 30)) { // we have a black pixel, switch to blue red = 0; green = 0; blue = 255; rgba = (alpha << 24) | (red << 16) | (green << 8) | (blue); image.setRGB(x,y,rgba); } } saveBufferedImage(image, "editedImage1.jpg"); // Get the graphics and paint a semi-transparent oval in the middle Graphics g = image.getGraphics(); g.setColor(new Color(255, 0, 0, 128)); // semi-transparent red g.fillOval(0, imageHeight/2-20, imageWidth, 40); saveBufferedImage(image, "editedImage2.jpg"); // Make a new image from scratch int width = 400, height = 200; image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); g = image.getGraphics(); g.setColor(Color.yellow); g.fillRect(0,0,width,height); // add some vertical bars g.setColor(Color.blue); for (int x=20; x