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

public GradientImage(int width, int height, Color[] colors, int alignment) {
    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
    this.alignment = alignment;
    this.width = width;
    this.height = height;
    this.colors = colors;
    rgbs = new int[colors.length];
    for (int i = 0; i < rgbs.length; i++) {
        rgbs[i] = colors[i].getRGB();/* w  w  w  .  j a  v a2  s.com*/
    }
    try {
        renderImage();
    } catch (Exception error) {
        error.printStackTrace();
    }
}

From source file:com.o2d.pkayjava.editor.proxy.ResolutionManager.java

public static BufferedImage imageResize(File file, float ratio) {
    BufferedImage destinationBufferedImage = null;
    try {//from  w w w  .  ja va2  s. c o  m
        BufferedImage sourceBufferedImage = ImageIO.read(file);
        if (ratio == 1.0) {
            return null;
        }
        // When image has to be resized smaller then 3 pixels we should leave it as is, as to ResampleOP limitations
        // But it should also trigger a warning dialog at the and of the import, to notify the user of non resized images.
        if (sourceBufferedImage.getWidth() * ratio < 3 || sourceBufferedImage.getHeight() * ratio < 3) {
            return null;
        }
        int newWidth = Math.max(3, Math.round(sourceBufferedImage.getWidth() * ratio));
        int newHeight = Math.max(3, Math.round(sourceBufferedImage.getHeight() * ratio));
        String name = file.getName();
        Integer[] patches = null;
        if (name.endsWith(EXTENSION_9PATCH)) {
            patches = NinePatchUtils.findPatches(sourceBufferedImage);
            sourceBufferedImage = NinePatchUtils.removePatches(sourceBufferedImage);

            newWidth = Math.round(sourceBufferedImage.getWidth() * ratio);
            newHeight = Math.round(sourceBufferedImage.getHeight() * ratio);
            System.out.println(sourceBufferedImage.getWidth());

            destinationBufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = destinationBufferedImage.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
            g2.drawImage(sourceBufferedImage, 0, 0, newWidth, newHeight, null);
            g2.dispose();

        } else {
            // resize with bilinear filter
            ResampleOp resampleOp = new ResampleOp(newWidth, newHeight);
            destinationBufferedImage = resampleOp.filter(sourceBufferedImage, null);
        }

        if (patches != null) {
            destinationBufferedImage = NinePatchUtils.convertTo9Patch(destinationBufferedImage, patches, ratio);
        }

    } catch (IOException ignored) {

    }

    return destinationBufferedImage;
}

From source file:TexturedText.java

/** Construct the object */
public TexturedText() {
    super();/* w  w  w  . j a va2  s  .c om*/
    setBackground(Color.white);
    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);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
}

From source file:org.jtalks.jcommune.service.nontransactional.ImageConverterTest.java

@DataProvider(name = "parameterResizeImage")
public Object[][] parameterResizeImage() {
    int widthWithAspectRatioOne = 4;
    int heightWithAspectRatioOne = 4;
    int widthWithAspectRationMoreThatOne = 5;
    int heightWithAspectRatioMoreThatOne = 4;
    return new Object[][] {
            { widthWithAspectRatioOne, heightWithAspectRatioOne, BufferedImage.TYPE_INT_RGB, "jpeg" },
            { widthWithAspectRationMoreThatOne, heightWithAspectRatioMoreThatOne, BufferedImage.TYPE_INT_ARGB,
                    "png" } };
}

From source file:org.jimcat.gui.borders.RoundedShadowBorder.java

/**
 * /*from www .j a v  a  2  s .c o m*/
 * paint this type of border
 * 
 * @see org.jimcat.gui.borders.RoundedBorder#paintBorder(java.awt.Component,
 *      java.awt.Graphics, int, int, int, int)
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Color borderColor = c.getBackground();

    // check if old image is still useable
    if (imageBuffer == null || width != lastWidth || height != lastHeight
            || !ObjectUtils.equals(borderColor, lastColor)) {
        // update image buffer
        imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        lastHeight = height;
        lastWidth = width;
        lastColor = borderColor;

        int shadow_width = SHADOW_WIDTH * 2;

        int xb = Math.max(x + SHADOW_WIDTH - SHADOW_DISPLACEMENT.x, x);
        int yb = Math.max(y + SHADOW_WIDTH - SHADOW_DISPLACEMENT.y, y);

        int xs = Math.max(x, x + SHADOW_DISPLACEMENT.x);
        int ys = Math.max(y, y + SHADOW_DISPLACEMENT.y);

        BufferedImage border = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics imgG = border.createGraphics();
        super.paintBorder(c, imgG, xb, yb, width - shadow_width - Math.abs(SHADOW_DISPLACEMENT.x),
                height - shadow_width - Math.abs(SHADOW_DISPLACEMENT.y));
        imgG.dispose();

        BufferedImage shadow = shadowRenderer.createShadow(border);

        Graphics2D g2 = (Graphics2D) imageBuffer.getGraphics();
        g2.drawImage(shadow, xs, ys, null);
        g2.drawImage(border, xb, yb, null);
        g2.dispose();
    }
    g.drawImage(imageBuffer, x, y, null);
}

From source file:PrintFromButton.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);
    buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);//from  w  w w  . jav  a 2s .  c  o m

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    Canvas3D d = new Canvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    // create an off Screen Buffer

    c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    u.getViewer().getView().addCanvas3D(c);

    // create the gui
    Button b = new Button("Print");
    b.addActionListener(this);
    Panel p = new Panel();
    p.add(b);
    add("North", p);

    u.addBranchGraph(scene);
}

From source file:com.joliciel.jochre.search.highlight.ImageSnippet.java

public BufferedImage getImage() {
    try {/* ww  w.java2 s  .co m*/
        BufferedImage originalImage = ImageIO.read(imageFile);
        BufferedImage imageSnippet = new BufferedImage(this.rectangle.getWidth(), this.rectangle.getHeight(),
                BufferedImage.TYPE_INT_ARGB);
        originalImage = originalImage.getSubimage(this.rectangle.getLeft(), this.rectangle.getTop(),
                this.rectangle.getWidth(), this.rectangle.getHeight());
        Graphics2D graphics2D = imageSnippet.createGraphics();
        graphics2D.drawImage(originalImage, 0, 0, this.rectangle.getWidth(), this.rectangle.getHeight(), null);
        int extra = 2;
        for (Rectangle rect : this.highlights) {
            graphics2D.setStroke(new BasicStroke(1));
            graphics2D.setPaint(Color.BLACK);
            graphics2D.drawRect(rect.getLeft() - this.rectangle.getLeft() - extra,
                    rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2),
                    rect.getHeight() + (extra * 2));
            graphics2D.setColor(new Color(255, 255, 0, 127));
            graphics2D.fillRect(rect.getLeft() - this.rectangle.getLeft() - extra,
                    rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2),
                    rect.getHeight() + (extra * 2));
        }
        return imageSnippet;
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:edu.kit.dama.ui.components.TextImage.java

/**
 * Get the bytes of the final image.//from  w  w w .j  a v  a  2 s . co m
 *
 * @return The byte array containing the bytes of the resulting image.
 *
 * @throws IOException if creating the image fails.
 */
public byte[] getBytes() throws IOException {
    Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(
            new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() {
                @Override
                public final int filterRGB(int x, int y, int rgb) {
                    return (rgb << 8) & 0xFF000000;
                }
            }));

    //create the actual image and overlay it by the transparent background
    BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = outputImage.createGraphics();
    g2d.drawImage(transparentImage, 0, 0, null);
    //draw the remaining stuff
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setColor(color);
    g2d.fillRoundRect(0, 0, size, size, 20, 20);
    g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f),
            Math.round((float) color.getBlue() * .9f)));
    g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20);

    Font font = new Font("Dialog", Font.BOLD, size - 4);
    g2d.setFont(font);
    g2d.setColor(Color.WHITE);

    String s = text.toUpperCase().substring(0, 1);
    FontMetrics fm = g2d.getFontMetrics();
    float x = ((float) size - (float) fm.stringWidth(s)) / 2f;
    float y = ((float) fm.getAscent()
            + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f;
    g2d.drawString(s, x, y);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ImageIO.write(outputImage, "png", bout);
    g2d.dispose();
    return bout.toByteArray();
}

From source file:BufferedImageThread.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension d = getSize();//from  w  ww  .  j a  va  2 s .c om

    bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();

    step(d.width, d.height);

    AffineTransform at = new AffineTransform();
    at.setToIdentity();
    at.translate(x, y);
    at.rotate(Math.toRadians(rotate));
    at.scale(scale, scale);
    big.drawImage(image, at, this);

    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage(bi, 0, 0, null);

    big.dispose();
}

From source file:ca.sqlpower.wabit.report.ResultSetRendererTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    this.query = new QueryCache(getContext());
    getWorkspace().addQuery(query, getSession());
    query.setDataSource((JDBCDataSource) getSession().getDataSources().getDataSource("regression_test"));

    getWorkspace().addChild(query, 0);/*from   w  w w.j  a va 2  s. c  o  m*/
    renderer = new ResultSetRenderer(query);
    parentCB = new ContentBox();
    parentCB.setContentRenderer(renderer);

    BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    graphics = image.getGraphics();

    Report report = new Report("report");
    report.getPage().addContentBox(parentCB);
    getWorkspace().addReport(report);
}