Java tutorial
import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.io.File; import javax.imageio.ImageIO; public class Main { public static void main(String[] args) throws Exception { int size = 120; int pad = 10; BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, size, size); g.setColor(Color.YELLOW); g.fillOval(pad, pad, size - (2 * pad), size - (2 * pad)); g.dispose(); BufferedImage image2 = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_BYTE_GRAY); ColorConvertOp op = new ColorConvertOp(bi.getColorModel().getColorSpace(), image2.getColorModel().getColorSpace(), null); op.filter(bi, image2); ImageIO.write(image2, "png", new File("c:/Java_Dev/image2.png")); } }