BufferedImage (double scale, int width, int height, Function<? super Graphics2D, Void> consumeGraphics) { @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage((int)ceil(width * scale), (int)ceil(height * scale), BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); try { double gScale = JreHiDpiUtil.isJreHiDPIEnabled() ? scale : 1; g.scale(gScale, gScale); g.setColor(Color.white); g.fillRect(0, 0, image.getWidth(), image.getHeight()); g.setColor(Color.black); consumeGraphics.apply(g); return image; } finally { g.dispose(); } }