Example usage for java.awt.image BufferedImage TYPE_4BYTE_ABGR

List of usage examples for java.awt.image BufferedImage TYPE_4BYTE_ABGR

Introduction

In this page you can find the example usage for java.awt.image BufferedImage TYPE_4BYTE_ABGR.

Prototype

int TYPE_4BYTE_ABGR

To view the source code for java.awt.image BufferedImage TYPE_4BYTE_ABGR.

Click Source Link

Document

Represents an image with 8-bit RGBA color components with the colors Blue, Green, and Red stored in 3 bytes and 1 byte of alpha.

Usage

From source file:Main.java

public static void main(String[] args) {
    final int width = 512;
    final int height = 512;
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics g = img.getGraphics();
    g.setColor(Color.black);/*from   w  w w  . java  2s.c  om*/
    g.fillRect(0, 0, width, height);
    g.setColor(Color.white);
    final double A = 8;
    final double B = 0.5;
    final double N = 4;
    final double scale = 128;
    final double zoom = 50;
    final double step = 1 / scale;
    Point last = null;
    final Point origin = new Point(width / 2, height / 2);

    for (double t = 0; t <= 2 * Math.PI; t += step) {
        final double r = zoom * polarFunction(t, A, B, N);
        final int x = (int) Math.round(r * Math.cos(t));
        final int y = (int) Math.round(r * Math.sin(t));
        Point next = new Point(x, y);
        if (last != null) {
            g.drawLine(origin.x + last.x, origin.y + last.y, origin.x + next.x, origin.y + next.y);
        }
        last = next;
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new JLabel(new ImageIcon(img)));
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Creates a static rectangular image with given color, width and height.
 *///from   www  .ja v a  2 s . c  o  m
public static Icon buildStaticImage(Color color, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            image.setRGB(x, y, color.getRGB());
        }
    }
    return new ImageIcon(image);
}

From source file:Main.java

public static BufferedImage generateOutline(BufferedImage source, Color color1, Color color2, boolean alpha) {
    int w = source.getWidth();
    int h = source.getHeight();
    BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            if (!testNeighbour(source, x, y, alpha)) {
                if (testNeighbours(source, x, y, alpha)) {
                    boolean a = ((x + y) % 10) <= 5;
                    result.setRGB(x, y, a ? color1.getRGB() : color2.getRGB());
                }//from   w ww  . ja v a  2s.c o m
            }
        }
    }
    return result;
}

From source file:SysTray.java

private Image getImage() throws HeadlessException {
    Icon defaultIcon = MetalIconFactory.getTreeHardDriveIcon();
    Image img = new BufferedImage(defaultIcon.getIconWidth(), defaultIcon.getIconHeight(),
            BufferedImage.TYPE_4BYTE_ABGR);
    defaultIcon.paintIcon(new Panel(), img.getGraphics(), 0, 0);
    return img;//  w w  w .  j a  va  2 s.  c  om
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.Canvas.java

public Canvas() {
    super();

    resizableBufferedImage = new ResizableBufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
}

From source file:com.us.servlet.AuthCode.java

protected void service(HttpServletRequest request, HttpServletResponse response) {
    final CodeAuth bean = AppHelper.CODE_AUTH;
    int width = NumberUtils.toInt(request.getParameter("width"), bean.getWidth());
    int height = NumberUtils.toInt(request.getParameter("height"), bean.getHeight());
    int x = width / (bean.getLength() + 1);
    int codeY = height - 4;
    int fontHeight = height - 2;
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = image.createGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    if (StringUtil.hasText(request.getParameter("bgcolor"))) {
        graphics.setBackground(ColorHelper.hex2RGB(request.getParameter("bgcolor")));
    }/*from w  w  w. j  av a 2 s  . co m*/
    graphics.fillRect(0, 0, width, height);
    graphics.setFont(new Font(bean.getFont(), Font.BOLD, fontHeight));
    graphics.drawRect(0, 0, width - 1, height - 1);
    // 
    if (bean.isBreakLine()) {
        for (int i = 0; i < 15; i++) {
            int x1 = RandomUtils.nextInt(width);
            int y1 = RandomUtils.nextInt(height);
            int x2 = RandomUtils.nextInt(12);
            int y2 = RandomUtils.nextInt(12);
            graphics.drawLine(x1, y1, x + x2, y1 + y2);
        }
    }
    char[] CHARSET_AREA = null;
    if (bean.getType().charAt(0) == '1') {
        CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, BIG_LETTERS);
    }
    if (bean.getType().charAt(1) == '1') {
        CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, SMALL_LETTER);
    }
    if (bean.getType().charAt(2) == '1') {
        CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, NUMBERS);
    }
    StringBuilder randomCode = new StringBuilder();
    for (int i = 0; i < bean.getLength(); i++) {
        String rand = String.valueOf(CHARSET_AREA[RandomUtils.nextInt(CHARSET_AREA.length)]);
        graphics.setColor(ColorHelper.color(RandomUtils.nextInt(255), RandomUtils.nextInt(255),
                RandomUtils.nextInt(255)));
        graphics.drawString(rand, (i + 1) * x, codeY);
        randomCode.append(rand);
    }
    HttpSession session = request.getSession();
    session.setAttribute(bean.getSessionKey(), randomCode.toString());
    // ?
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/png");
    try {
        // Servlet?
        ServletOutputStream sos = response.getOutputStream();
        ImageIO.write(image, "png", sos);
        sos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.l1j5.web.common.utils.ImageUtils.java

public static void getGifImageThumbnail(BufferedInputStream stream_file, String save, String type, int w,
        int h) {/*from  ww w.  j  a v a2s.  com*/

    GifDecoder dec = new GifDecoder();
    AnimatedGifEncoder enc = new AnimatedGifEncoder();
    dec.read(stream_file);

    int cnt = dec.getFrameCount();

    int delay = 0;
    int width = 0;
    int height = 0;

    try {
        enc.start(save);
        enc.setRepeat(0);

        for (int i = 0; i < cnt; i++) {
            BufferedImage frame = dec.getFrame(i);
            delay = dec.getDelay(i);

            width = frame.getWidth();
            height = frame.getHeight();
            if (w < width) {
                width = w;
            }
            if (h < height) {
                height = h;
            }

            BufferedImage destimg = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g = destimg.createGraphics();

            g.drawImage(frame, 0, 0, width, height, null);
            enc.setDelay(delay);

            enc.addFrame(destimg);
        }

        enc.finish();
    } catch (Exception ex) {
        log.error(ex);
    }
}

From source file:com.vaadin.testbench.screenshot.ImageUtil.java

/**
 * Extract magical image properties used by the getBlock function.
 * //from w  w w.  j  av  a  2  s. co m
 * @param image
 *            a BufferedImage
 * @return an ImageProperties descriptor object
 */
public static final ImageProperties getImageProperties(final BufferedImage image) {
    final int imageType = image.getType();
    ImageProperties p = new ImageProperties();
    p.image = image;
    p.raster = image.getRaster();
    p.alpha = imageType == TYPE_INT_ARGB || imageType == BufferedImage.TYPE_4BYTE_ABGR;
    boolean rgb = imageType == TYPE_INT_ARGB || imageType == TYPE_INT_RGB;
    boolean bgr = imageType == BufferedImage.TYPE_INT_BGR || imageType == BufferedImage.TYPE_3BYTE_BGR
            || imageType == BufferedImage.TYPE_4BYTE_ABGR;
    p.width = image.getWidth();
    p.height = image.getHeight();
    p.fallback = !(rgb || bgr);
    return p;
}

From source file:org.geotools.renderer.chart.ChartGraphicFactory.java

BufferedImage drawChart(JFreeChart chart, int w, int h) {
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D gr = bi.createGraphics();
    try {/*from ww w  .j a  va  2 s  . c o m*/
        chart.draw(gr, new Rectangle2D.Double(0, 0, w, h));
    } finally {
        gr.dispose();
    }

    return bi;
}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * {@inheritDoc}/*from  w  ww  . j ava  2s.  c o  m*/
 */
public BufferedImage createPhylogenyImage(PhylogenyTreeNode phylogenyTree, int imageWidth, int imageHeight) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Creating phylogeny image for: "
                + phylogenyTree.resolveToSingleStrainLeafNodes(0.0).toNewickFormat());
    }

    BufferedImage bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = bi.createGraphics();
    graphics.setStroke(LINE_STROKE);
    graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setColor(Color.BLACK);

    this.paintPhylogenyTree(graphics, phylogenyTree, imageWidth, imageHeight);

    return bi;
}