Java BufferedImage Operation doInGraphics(final BufferedImage image, final Consumer consumer)

Here you can find the source of doInGraphics(final BufferedImage image, final Consumer consumer)

Description

do In Graphics

License

Open Source License

Declaration

public static void doInGraphics(final BufferedImage image, final Consumer<Graphics2D> consumer) 

Method Source Code


//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();
    }
}

Related

  1. darkenImage(final BufferedImage image, final float darken)
  2. declareNewBufferedImage(int x, int y)
  3. declareNewBufferedImageAndCopy(BufferedImage img)
  4. depalettize(BufferedImage img, int maxBytes)
  5. determineBackgroundColor(BufferedImage bim)
  6. duplicate(BufferedImage image)
  7. DuplicateBufferedImage(BufferedImage bi)
  8. duplicateImage(BufferedImage image)
  9. dye(BufferedImage image, Color color)