Here you can find the source of doInGraphics(final BufferedImage image, final Consumer
public static void doInGraphics(final BufferedImage image, final Consumer<Graphics2D> consumer)
//package com.java2s; /*//from w ww .ja va 2 s. c o m * Copyright ? 2016 spypunk <spypunk@gmail.com> * * This work is free. You can redistribute it and/or modify it under the * terms of the Do What The Fuck You Want To Public License, Version 2, * as published by Sam Hocevar. See the COPYING file for more details. */ import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.util.function.Consumer; public class Main { public static void doInGraphics(final BufferedImage image, final Consumer<Graphics2D> consumer) { final Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setColor(Color.BLACK); graphics.fillRect(0, 0, image.getWidth(), image.getHeight()); consumer.accept(graphics); graphics.dispose(); } }