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:AlphaCompositeSRCOUT.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;

    int w = getSize().width;
    int h = getSize().height;

    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();

    ac = AlphaComposite.getInstance(compositeRule, alphaValue);

    big.setColor(Color.red);/*from  ww  w  .  j  a  va  2 s  .  c o  m*/
    big.drawString("Destination", w / 4, h / 4);
    big.fill(new Ellipse2D.Double(0, h / 3, 2 * w / 3, h / 3));

    big.setColor(Color.blue);
    big.drawString("Source", 3 * w / 4, h / 4);

    big.setComposite(ac);
    big.fill(new Ellipse2D.Double(w / 3, h / 3, 2 * w / 3, h / 3));

    g2D.drawImage(bi, null, 0, 0);
}

From source file:eu.novait.imageresizer.helpers.ImageConverter.java

public void process() throws IOException {
    BufferedImage inImage = ImageIO.read(this.file);
    double ratio = (double) inImage.getWidth() / (double) inImage.getHeight();
    int w = this.width;
    int h = this.height;
    if (inImage.getWidth() >= inImage.getHeight()) {
        w = this.width;
        h = (int) Math.round(w / ratio);
    } else {/*from   w  w w. j  ava2  s.  c o m*/
        h = this.height;
        w = (int) Math.round(ratio * h);
    }
    int type = inImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : inImage.getType();
    BufferedImage outImage = new BufferedImage(w, h, type);
    Graphics2D g = outImage.createGraphics();
    g.drawImage(inImage, 0, 0, w, h, null);
    g.dispose();
    String ext = FilenameUtils.getExtension(this.file.getAbsolutePath());
    String t = "jpg";
    switch (ext) {
    case "png":
        t = "png";
        break;
    }
    ImageIO.write(outImage, t, this.outputfile);
}

From source file:org.apache.fop.visual.BitmapComparator.java

/**
 * Builds a new BufferedImage that is the difference between the two input images
 * @param ref the reference bitmap/*from   w  w w .  j  a  va  2s.c o  m*/
 * @param gen the newly generated bitmap
 * @return the diff bitmap
 */
public static BufferedImage buildDiffImage(BufferedImage ref, BufferedImage gen) {
    BufferedImage diff = new BufferedImage(ref.getWidth(), ref.getHeight(), BufferedImage.TYPE_INT_ARGB);
    WritableRaster refWR = ref.getRaster();
    WritableRaster genWR = gen.getRaster();
    WritableRaster dstWR = diff.getRaster();

    boolean refPre = ref.isAlphaPremultiplied();
    if (!refPre) {
        ColorModel cm = ref.getColorModel();
        cm = GraphicsUtil.coerceData(refWR, cm, true);
        ref = new BufferedImage(cm, refWR, true, null);
    }
    boolean genPre = gen.isAlphaPremultiplied();
    if (!genPre) {
        ColorModel cm = gen.getColorModel();
        cm = GraphicsUtil.coerceData(genWR, cm, true);
        gen = new BufferedImage(cm, genWR, true, null);
    }

    int w = ref.getWidth();
    int h = ref.getHeight();

    int y, i, val;
    int[] refPix = null;
    int[] genPix = null;
    for (y = 0; y < h; y++) {
        refPix = refWR.getPixels(0, y, w, 1, refPix);
        genPix = genWR.getPixels(0, y, w, 1, genPix);
        for (i = 0; i < refPix.length; i++) {
            // val = ((genPix[i] - refPix[i]) * 5) + 128;
            val = ((refPix[i] - genPix[i]) * 10) + 128;
            if ((val & 0xFFFFFF00) != 0) {
                if ((val & 0x80000000) != 0) {
                    val = 0;
                } else {
                    val = 255;
                }
            }
            genPix[i] = val;
        }
        dstWR.setPixels(0, y, w, 1, genPix);
    }

    if (!genPre) {
        ColorModel cm = gen.getColorModel();
        cm = GraphicsUtil.coerceData(genWR, cm, false);
    }

    if (!refPre) {
        ColorModel cm = ref.getColorModel();
        cm = GraphicsUtil.coerceData(refWR, cm, false);
    }

    return diff;
}

From source file:RotateImage45Degrees.java

public RotateImage45Degrees(String imageFile) {
    addNotify();//  ww w .  j a v  a  2  s  .  com
    frameInsets = getInsets();
    inputImage = Toolkit.getDefaultToolkit().getImage(imageFile);

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(inputImage, 0);
    try {
        mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    sourceBI = new BufferedImage(inputImage.getWidth(null), inputImage.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) sourceBI.getGraphics();
    g.drawImage(inputImage, 0, 0, null);

    AffineTransform at = new AffineTransform();

    // scale image
    at.scale(2.0, 2.0);

    // rotate 45 degrees around image center
    at.rotate(45.0 * Math.PI / 180.0, sourceBI.getWidth() / 2.0, sourceBI.getHeight() / 2.0);

    /*
     * translate to make sure the rotation doesn't cut off any image data
     */
    AffineTransform translationTransform;
    translationTransform = findTranslation(at, sourceBI);
    at.preConcatenate(translationTransform);

    // instantiate and apply affine transformation filter
    BufferedImageOp bio;
    bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    destinationBI = bio.filter(sourceBI, null);

    int frameInsetsHorizontal = frameInsets.right + frameInsets.left;
    int frameInsetsVertical = frameInsets.top + frameInsets.bottom;
    setSize(destinationBI.getWidth() + frameInsetsHorizontal, destinationBI.getHeight() + frameInsetsVertical);
    show();
}

From source file:examples.gp.monalisa.gui.GeneticDrawingView.java

public GeneticDrawingView(SingleFrameApplication app) {
    super(app);// ww  w  .ja  v  a2  s  .c o m
    initComponents();
    ResourceMap resourceMap = getResourceMap();
    ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon");
    targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0);
    fittestDrawingView = new FittestDrawingView();
    fittestDrawingView.setVisible(false);
    fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight());
}

From source file:script.imglib.analysis.ChartUtils.java

public static final Image<RGBALegacyType> asImage(final JFreeChart chart, int width, int height) {
    ChartPanel panel = new ChartPanel(chart);
    Dimension d = panel.getPreferredSize();
    if (-1 == width && -1 == height) {
        width = d.width;/*w w  w  .  j  a  v  a2 s  .  c  o  m*/
        height = d.height;
        panel.setSize(d);
    } else {
        panel.setSize(width, height);
    }
    layoutComponent(panel);
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    if (!panel.isOpaque()) {
        g.setColor(panel.getBackground());
        g.fillRect(0, 0, width, height);
    }
    panel.paint(g);
    int[] pixels = new int[width * height];
    PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }
    g.dispose();

    Array<RGBALegacyType, IntAccess> a = new Array<RGBALegacyType, IntAccess>(new ArrayContainerFactory(),
            new IntArray(pixels), new int[] { width, height }, 1);
    // create a Type that is linked to the container
    final RGBALegacyType linkedType = new RGBALegacyType(a);
    // pass it to the DirectAccessContainer
    a.setLinkedType(linkedType);

    return new Image<RGBALegacyType>(a, new RGBALegacyType());
}

From source file:jadx.core.utils.android.Res9patchStreamDecoder.java

public void decode(InputStream in, OutputStream out) throws JadxException {
    try {//from   w  ww .j a va 2  s . c o  m
        byte[] data = IOUtils.toByteArray(in);

        BufferedImage im = ImageIO.read(new ByteArrayInputStream(data));
        int w = im.getWidth(), h = im.getHeight();

        BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
        im2.createGraphics().drawImage(im, 1, 1, w, h, null);

        NinePatch np = getNinePatch(data);
        drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
        drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom);

        int[] xDivs = np.xDivs;
        for (int i = 0; i < xDivs.length; i += 2) {
            drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]);
        }

        int[] yDivs = np.yDivs;
        for (int i = 0; i < yDivs.length; i += 2) {
            drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]);
        }

        ImageIO.write(im2, "png", out);
    } catch (IOException | NullPointerException ex) {
        throw new JadxException(ex.toString());
    }
}

From source file:gd.gui.GeneticDrawingView.java

public GeneticDrawingView(SingleFrameApplication app) {
    super(app);// w  w w .  ja v a 2 s. c o m

    initComponents();

    ResourceMap resourceMap = getResourceMap();
    ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon");
    targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0);
    ProblemInstance.currentImage = targetImage;
    ProblemInstance.view = this;

    fittestDrawingView = new FittestDrawingView();
    fittestDrawingView.setVisible(false);
    fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight());

    try {
        startEvolution();
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

private BufferedImage createImage() {
    BufferedImage bim;/*from   w  ww .  java  2 s. com*/

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    return bim;
}

From source file:com.iiitd.qre.CreateZSignedQR.java

public static BufferedImage toBufferedImage(ByteMatrix matrix) {
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int scale = 6;
    int margin = 3;
    BufferedImage image = new BufferedImage(scale * (width + 2 * margin), scale * (height + 2 * margin),
            BufferedImage.TYPE_INT_ARGB);

    int imgX, imgY = margin * scale;
    for (int y = 0; y < height; y++) {
        for (int i = 0; i < scale; ++i) {
            imgX = margin * scale;/* w ww.  ja  v  a2 s.  c  o  m*/
            for (int x = 0; x < width; x++) {
                for (int j = 0; j < scale; ++j) {
                    if (matrix.get(x, y) != 0)
                        image.setRGB(imgX, imgY, BLACK);
                    ++imgX;
                }
            }
            ++imgY;
        }
    }
    return image;
}