Example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Prototype

Object VALUE_TEXT_ANTIALIAS_ON

To view the source code for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Click Source Link

Document

Text antialiasing hint value -- text rendering is done with some form of antialiasing.

Usage

From source file:processing.app.Theme.java

static public Graphics2D setupGraphics2D(Graphics graphics) {
    Graphics2D g = (Graphics2D) graphics;
    if (PreferencesData.getBoolean("editor.antialias")) {
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }/*from w  ww  . jav a2s  .c o  m*/
    return g;
}

From source file:test.unit.be.fedict.eid.applet.service.KmlGeneratorTest.java

@Test
public void identityWithAddressAndPhotoKml() throws Exception {
    // setup//from ww w .  ja v a  2  s.c om
    Identity identity = new Identity();
    identity.name = "Test Name";
    identity.firstName = "Test First name";
    identity.dateOfBirth = new GregorianCalendar();
    identity.gender = Gender.MALE;

    Address address = new Address();
    address.streetAndNumber = "Test Street 1A";
    address.zip = "1234";
    address.municipality = "Test Municipality";

    BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = (Graphics2D) image.getGraphics();
    RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setRenderingHints(renderingHints);
    graphics.setColor(Color.WHITE);
    graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1);
    graphics.setFont(new Font("Dialog", Font.BOLD, 20));
    graphics.setColor(Color.BLACK);
    graphics.drawString("Test Photo", 0, 200 / 2);
    graphics.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpg", baos);
    byte[] photo = baos.toByteArray();

    EIdData eIdData = new EIdData();
    eIdData.identity = identity;
    eIdData.address = address;
    eIdData.photo = photo;

    // operate
    byte[] document = this.testedInstance.generateKml(eIdData);

    // verify
    assertNotNull(document);
    assertTrue(document.length > 0);

    toTmpFile(document);
}

From source file:test.unit.be.fedict.eid.applet.service.PdfGeneratorTest.java

@Test
public void identityWithAddressAndPhotoPdf() throws Exception {
    // setup//from w ww  . j  a v a 2 s. c o  m
    Identity identity = new Identity();
    identity.name = "Test Name";
    identity.firstName = "Test First name";
    identity.dateOfBirth = new GregorianCalendar();
    identity.gender = Gender.MALE;

    Address address = new Address();
    address.streetAndNumber = "Test Street 1A";
    address.zip = "1234";
    address.municipality = "Test Municipality";

    BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = (Graphics2D) image.getGraphics();
    RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setRenderingHints(renderingHints);
    graphics.setColor(Color.WHITE);
    graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1);
    graphics.setFont(new Font("Dialog", Font.BOLD, 20));
    graphics.setColor(Color.BLACK);
    graphics.drawString("Test Photo", 0, 200 / 2);
    graphics.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpg", baos);
    byte[] photo = baos.toByteArray();

    EIdData eIdData = new EIdData();
    eIdData.identity = identity;
    eIdData.address = address;
    eIdData.photo = photo;

    // operate
    byte[] document = this.testedInstance.generatePdf(eIdData);

    // verify
    assertNotNull(document);
    assertTrue(document.length > 0);

    toTmpFile(document);
}

From source file:test.unit.be.fedict.eid.applet.service.VcardGeneratorTest.java

@Test
public void identityWithAddressAndPhotoVcard() throws Exception {
    // setup//from   w ww .j a va2  s.co m
    Identity identity = new Identity();
    identity.name = "Test Name";
    identity.firstName = "Test First name";
    identity.dateOfBirth = new GregorianCalendar();
    identity.gender = Gender.MALE;

    Address address = new Address();
    address.streetAndNumber = "Test Street 1A";
    address.zip = "1234";
    address.municipality = "Test Municipality";

    BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = (Graphics2D) image.getGraphics();
    RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setRenderingHints(renderingHints);
    graphics.setColor(Color.WHITE);
    graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1);
    graphics.setFont(new Font("Dialog", Font.BOLD, 20));
    graphics.setColor(Color.BLACK);
    graphics.drawString("Test Photo", 0, 200 / 2);
    graphics.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpg", baos);
    byte[] photo = baos.toByteArray();

    EIdData eIdData = new EIdData();
    eIdData.identity = identity;
    eIdData.address = address;
    eIdData.photo = photo;

    // operate
    byte[] document = this.testedInstance.generateVcard(eIdData);

    // verify
    assertNotNull(document);
    assertTrue(document.length > 0);

    toTmpFile(document);
}

From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java

private void generateScatterPlot() throws IOException {
    final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final FontMetrics fm = g2.getFontMetrics();
    final String filename = "throughputency.png";
    final File imageFile = new File(filename);

    final int height = 940;
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    for (final long timestamp : timestamps) {
        final double ts = timestamp / 1000.0;
        if (ts < min) {
            min = ts;/*from   w w  w .  j  av a  2  s.  com*/
        }
        if (ts > max) {
            max = ts;
        }
    }
    final double stepY = height / max;

    g2.setColor(Color.white);
    g2.fillRect(0, 0, 1800, 1000);
    g2.setColor(Color.black);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString("Latency ScatterPlot (microseconds)",
            900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2, 20);
    g2.drawString("" + max, 10, 20);
    g2.drawLine(100, 20, 100, 960);
    g2.drawLine(100, 960, 1790, 960);
    int start = 0;
    int end = 100;
    final double width = 1690.0 / 7.0;
    g2.setColor(Color.red);
    plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]);

    start = 100;
    end = 1100;
    g2.setColor(Color.green);
    plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]);

    start = 1100;
    end = 11100;
    g2.setColor(Color.blue);
    plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]);

    start = 11100;
    end = 111100;
    g2.setColor(Color.cyan);
    plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]);

    start = 111100;
    end = 1111100;
    g2.setColor(Color.magenta);
    plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]);

    start = 1111100;
    end = 11111100;
    g2.setColor(Color.yellow);
    plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]);

    start = 11111100;
    end = 41111100;
    g2.setColor(Color.orange);
    plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]);

    ImageIO.write(image, "png", imageFile);
}

From source file:z.tool.util.image.ImageUtil.java

/**
 * ??(???)/*from w w  w .  ja  v a2  s.co m*/
 */
public static void mergeResource(int bufferedImageType, InputStream inputStream, ImageType destType,
        OutputStream outputStream, int newHeight, int newWidth, Mergeable mergeable, Mergeable... mergeables) {
    if (null == inputStream) {
        throw new IllegalArgumentException("inputStream is null");
    }

    if (null == destType) {
        throw new IllegalArgumentException("destType is null");
    }

    if (null == outputStream) {
        throw new IllegalArgumentException("outputStream is null");
    }

    try {
        Image srcImage = ImageIO.read(inputStream);

        // ?
        int srcImageWidth = srcImage.getWidth(null);
        int srcImageHeight = srcImage.getHeight(null);

        // ????
        if (0 == newWidth || 0 == newHeight) {
            newWidth = srcImageWidth;
            newHeight = srcImageHeight;
        }

        BufferedImage distImage = new BufferedImage(newWidth, newHeight, bufferedImageType);

        // 
        Graphics2D graphics2d = distImage.createGraphics();
        graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        graphics2d.drawImage(srcImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null);

        // ??(?)
        mergeable.draw(graphics2d);

        // ??(?)
        if (null != mergeables && mergeables.length > 0) {
            for (Mergeable d : mergeables) {
                d.draw(graphics2d);
            }
        }

        // ?
        ImageIO.write(distImage, destType.name(), outputStream);
    } catch (IOException e) {
        LOG.error("method:mergeResource,destType:" + destType + ",newHeight:" + newHeight + ",newWidth:"
                + newWidth + ",errorMsg:" + e.getMessage(), e);
        throw new HumanNeededError(Error.IO_ERROR);
    }
}