Example usage for java.awt.image BufferedImage TYPE_INT_ARGB

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

Introduction

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

Prototype

int TYPE_INT_ARGB

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

Click Source Link

Document

Represents an image with 8-bit RGBA color components packed into integer pixels.

Usage

From source file:com.joliciel.jochre.graphics.VectorizerImpl.java

public BufferedImage drawArrayLists(JochreImage jochreImage) {
    long startTime = (new Date()).getTime();
    BufferedImage vectorizedImage = new BufferedImage(jochreImage.getWidth(), jochreImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = vectorizedImage.createGraphics();
    graphics2D.setStroke(new BasicStroke(1));
    graphics2D.setPaint(Color.BLACK);

    for (Paragraph paragraph : jochreImage.getParagraphs()) {
        for (RowOfShapes row : paragraph.getRows()) {
            for (GroupOfShapes group : row.getGroups()) {
                for (Shape shape : group.getShapes()) {
                    List<LineSegment> lines = this.vectorize(shape);

                    for (LineSegment line : lines)
                        graphics2D.drawLine(shape.getLeft() + line.getStartX(),
                                shape.getTop() + line.getStartY(), shape.getLeft() + line.getEndX(),
                                shape.getTop() + line.getEndY());
                }/*from ww  w .j av a 2 s.  c om*/
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        long endTime = (new Date()).getTime();
        long diff = endTime - startTime;
        LOG.debug("Time elapsed: " + ((double) diff / 1000));
    }
    return vectorizedImage;
}

From source file:net.sf.jasperreports.charts.util.ImageChartRendererFactory.java

@Override
public Renderable getRenderable(JasperReportsContext jasperReportsContext, JFreeChart chart,
        ChartHyperlinkProvider chartHyperlinkProvider, Rectangle2D rectangle) {
    int dpi = JRPropertiesUtil.getInstance(jasperReportsContext)
            .getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72);
    double scale = dpi / 72d;

    BufferedImage bi = new BufferedImage((int) (scale * (int) rectangle.getWidth()),
            (int) (scale * rectangle.getHeight()), BufferedImage.TYPE_INT_ARGB);

    List<JRPrintImageAreaHyperlink> areaHyperlinks = null;

    Graphics2D grx = bi.createGraphics();
    try {//from   www.  j  a v  a2  s  .c o m
        grx.scale(scale, scale);

        if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) {
            areaHyperlinks = ChartUtil.getImageAreaHyperlinks(chart, chartHyperlinkProvider, grx, rectangle);
        } else {
            chart.draw(grx, rectangle);
        }
    } finally {
        grx.dispose();
    }

    try {
        return new SimpleDataRenderer(
                JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG),
                areaHyperlinks);
    } catch (JRException e) {
        throw new JRRuntimeException(e);
    }
}

From source file:AttributesApp.java

public AttributesApp() {
    setBackground(Color.lightGray);
    setSize(500, 200);/*from   w  w  w .  j a  v  a  2 s.c  o m*/

    attribString = new AttributedString(text);

    GeneralPath star = new GeneralPath();
    star.moveTo(0, 0);
    star.lineTo(10, 30);
    star.lineTo(-10, 10);
    star.lineTo(10, 10);
    star.lineTo(-10, 30);
    star.closePath();
    GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false);
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1);

    int index = text.indexOf("Java Source");
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7);
    Font font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 7);

    loadImage();
    BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bimage.createGraphics();
    big.drawImage(image, null, this);
    GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0);

    index = text.indexOf("Java");
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index);

    font = new Font("serif", Font.BOLD, 60);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 4);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes.

    index = text.indexOf("source");
    attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2);

    index = text.indexOf("and support");
    font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 10);

    attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes.
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes.
}

From source file:ImageTransferTest.java

public ImageTransferFrame() {
    setTitle("ImageTransferTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    label = new JLabel();
    image = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.WHITE);//from   w ww  .  j av  a2  s .c  o m
    g.fillRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    g.setColor(Color.RED);
    g.fillOval(DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2);

    label.setIcon(new ImageIcon(image));
    add(new JScrollPane(label), BorderLayout.CENTER);
    JPanel panel = new JPanel();

    JButton copyButton = new JButton("Copy");
    panel.add(copyButton);
    copyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            copy();
        }
    });

    JButton pasteButton = new JButton("Paste");
    panel.add(pasteButton);
    pasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            paste();
        }
    });

    add(panel, BorderLayout.SOUTH);
}

From source file:com.frostwire.gui.library.LibraryCoverArt.java

public LibraryCoverArt() {
    background = new BufferedImage(350, 350, BufferedImage.TYPE_INT_ARGB);
    defaultCoverArt = GUIMediator.getThemeImage("default_cover_art").getImage();
    setFile(null);//from w  w  w .  ja va 2  s . c  om
    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            updateTheme();
        }
    });
    ThemeMediator.addThemeObserver(this);
}

From source file:RGBGrayFilter.java

/**
 * Returns an icon with a disabled appearance. This method is used
 * to generate a disabled icon when one has not been specified.
 *
 * @param component the component that will display the icon, may be null.
 * @param icon the icon to generate disabled icon from.
 * @return disabled icon, or null if a suitable icon can not be generated.
 *//* w  w  w.j a  va  2 s  .  c o m*/
public static Icon getDisabledIcon(JComponent component, Icon icon) {
    if ((icon == null) || (component == null) || (icon.getIconWidth() == 0) || (icon.getIconHeight() == 0)) {
        return null;
    }
    Image img;
    if (icon instanceof ImageIcon) {
        img = ((ImageIcon) icon).getImage();
    } else {
        img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
    }

    ImageProducer producer = new FilteredImageSource(img.getSource(), new RGBGrayFilter());

    return new ImageIcon(component.createImage(producer));
}

From source file:org.apache.fop.afp.svg.AFPGraphicsConfiguration.java

/**
 * Construct a buffered image with an alpha channel, unless
 * transparencty is OPAQUE (no alpha at all).
 *
 * @param width the width of the image//from   w  w w.jav  a2  s . c  o m
 * @param height the height of the image
 * @param transparency the alpha value of the image
 * @return the new buffered image
 */
public BufferedImage createCompatibleImage(int width, int height, int transparency) {
    if (transparency == Transparency.OPAQUE) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    } else {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    }
}

From source file:com.fun.util.TesseractUtil.java

/**
 * //  w  w w  .  j  av a2 s  .com
 *
 * @param imageFile
 * @param times
 * @param targetFile
 * @throws IOException
 */
private static void scaled(File imageFile, int times, File targetFile) throws IOException {
    BufferedImage image = ImageIO.read(imageFile);
    int targetWidth = image.getWidth() * times;
    int targetHeight = image.getHeight() * times;
    int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type);
    Graphics2D g2 = tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(image, 0, 0, targetWidth, targetHeight, null);
    g2.dispose();
    ImageIO.write(tmp, "png", targetFile);
}

From source file:org.web4thejob.web.util.MediaUtil.java

public static BufferedImage createThumbnail(byte[] bytes) {
    Image image = getImage(bytes);
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedImage.createGraphics();
    g.drawImage(image.toImageIcon().getImage(), 0, 0, null);
    g.dispose();// w  w w  .  java 2s .c  o  m
    return createThumbnail(bufferedImage);
}

From source file:com.tdclighthouse.prototype.servlets.JLatexServlet.java

private synchronized BufferedImage generateImage(String latex) {
    TeXFormula formula = new TeXFormula(latex);
    TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
    icon.setInsets(new Insets(5, 5, 5, 5));

    BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    g2.setColor(Color.white);/*  ww w  .  j a va 2  s.c o  m*/
    g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
    JLabel jl = new JLabel();
    jl.setForeground(new Color(0, 0, 0));
    icon.paintIcon(jl, g2, 0, 0);
    return image;
}