disable Antialiasing - Java 2D Graphics

Java examples for 2D Graphics:Graphics

Description

disable Antialiasing

Demo Code


//package com.java2s;

import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.RenderingHints;

public class Main {
    public static void disableAntialiasing(Graphics g) {
        if (g instanceof Graphics2D) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_OFF);
        } else {//  w w w  .j  a  v  a2  s .  co m
            throw new RuntimeException("Need a graphics2D object");
        }
    }
}

Related Tutorials