Example usage for java.awt.image BufferedImage BufferedImage

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

Introduction

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

Prototype

public BufferedImage(int width, int height, int imageType) 

Source Link

Document

Constructs a BufferedImage of one of the predefined image types.

Usage

From source file:ConvolveIt.java

public ConvolveIt() {
    int width = image.getWidth(this);
    int height = image.getHeight(this);
    bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bufferedImage.createGraphics();
    AffineTransform affineTransform = new AffineTransform();
    big.drawImage(image, affineTransform, this);
    Kernel kernel = new Kernel(3, 3, SHARP);
    convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
}

From source file:ImageComposite.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    BufferedImage buffImg = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);

    gbi.drawImage(a, 40, 30, null);/*from  w  w w . j a va 2 s.  c o m*/
    gbi.setComposite(ac);
    gbi.drawImage(b, 0, 0, null);

    g2d.drawImage(buffImg, 20, 20, null);
}

From source file:DoubleBufferWithBufferedImage.java

public DoubleBufferWithBufferedImage() {
    setSize(300, 300);//from  w  w w . java 2 s  .c  om
    Dimension d = getSize();
    w = d.width;
    h = d.height;
    buffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

public static BufferedImage renderAnimGrid(int xAngleMin, int xAngleMax, int xSteps, int yAngleMin,
        int yAngleMax, int ySteps) {
    BufferedImage grid = new BufferedImage(ySteps * size, xSteps * size, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) grid.getGraphics();
    for (int x = 0; x < xSteps; ++x) {
        double xAngle = xAngleMin + (xAngleMax - xAngleMin) * (xSteps == 1 ? 0.5 : (x / (double) (xSteps - 1)));
        Matrix4d matRotX = new Matrix4d();
        matRotX.setIdentity();/*from  w  w  w.jav  a2s.  c  o  m*/
        matRotX.rotX(Math.toRadians(xAngle));
        for (int y = 0; y < ySteps; ++y) {
            double yAngle = yAngleMin
                    + (yAngleMax - yAngleMin) * (ySteps == 1 ? 0.5 : (y / (double) (ySteps - 1)));
            Matrix4d matRotY = new Matrix4d();
            matRotY.setIdentity();
            matRotY.rotY(Math.toRadians(yAngle));
            additional_rotation.mul(matRotY, matRotX);
            BufferedImage bi = createBufferedImageFromRGB(draw(size, size, aam, aap));
            g2.drawImage(bi,
                    new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
                    (ySteps - 1 - y) * size, x * size);
        }
    }
    return grid;
}

From source file:ImageDuplicity.java

private void createOffscreenImage() {
    Dimension d = getSize();/*from w w w .j av a 2  s  .  co  m*/
    int width = d.width;
    int height = d.height;
    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = image.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    try {
        String filename = "largeJava2sLogo.jpg";
        InputStream in = getClass().getResourceAsStream(filename);
        JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
        BufferedImage image = decoder.decodeAsBufferedImage();
        in.close();
        g2.drawImage(image, 0, 0, width, height, null);
    } catch (Exception e) {
        System.out.print(e);
    }

    g2.setStroke(new BasicStroke(2));
    Color[] colors = { Color.red, Color.blue, Color.green };
    for (int i = -32; i < 40; i += 8) {
        g2.setPaint(colors[Math.abs(i) % 3]);
        g2.drawOval(i, i, width - i * 2, height - i * 2);
    }
}

From source file:ImageUtil.java

public static BufferedImage crop(BufferedImage src, int width, int height) throws IOException {
    int x = src.getWidth() / 2 - width / 2;
    int y = src.getHeight() / 2 - height / 2;

    //        System.out.println("---" + src.getWidth() + " - " + src.getHeight() + " - " + x + " - " + y);

    BufferedImage clipping = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//src.getType());  
    Graphics2D area = (Graphics2D) clipping.getGraphics().create();
    area.drawImage(src, 0, 0, clipping.getWidth(), clipping.getHeight(), x, y, x + clipping.getWidth(),
            y + clipping.getHeight(), null);
    area.dispose();/* w ww .  ja v  a 2s.co m*/

    return clipping;
}

From source file:ImageProc.java

public static void imagesc(File file, int[][] classificationMat, int nClass, int imgDim1, int imgDim2) {
    BufferedImage image = new BufferedImage(imgDim2, imgDim1, BufferedImage.TYPE_INT_RGB);
    int index, rgb;
    float[][] jet = colormapJet(nClass);
    for (int i = 0; i < imgDim1; i++) {
        for (int j = 0; j < imgDim2; j++) {
            index = classificationMat[i][j];
            if (index == -1) {
                image.setRGB(j, i, Color.BLACK.getRGB());
            } else {
                rgb = new Color(jet[index][0], jet[index][1], jet[index][2]).getRGB();
                image.setRGB(j, i, rgb);
            }//from w ww .j a  v  a2s . c  o  m
        }
    }
    try {
        ImageIO.write(image, "png", file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:GraphicsInfo.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    GraphicsConfiguration gc = g2d.getDeviceConfiguration();
    printModelType(gc.getColorModel());/*from   w w  w  . ja  v  a 2  s.c  o  m*/
    BufferedImage bi = new BufferedImage(20, 20, BufferedImage.TYPE_BYTE_INDEXED);
    Graphics2D g2d2 = bi.createGraphics();
    GraphicsConfiguration gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
    bi = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
    g2d2 = bi.createGraphics();
    gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
    bi = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_565_RGB);
    g2d2 = bi.createGraphics();
    gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
}

From source file:Main.java

/**
 * Takes a snapshot of the target component.
 *
 * @param component the component to draw
 * @param usePrint  whether <tt>print()</tt> or <tt>paint()</tt> is used to grab the snapshot
 * @return a Graphics compatible image of the component
 *//*w ww.  j  a  v  a  2s .  com*/
public static Image takeSnapshot(Component component, boolean usePrint) {
    BufferedImage image = null;
    GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = genv.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    if (gc.getColorModel().hasAlpha()) {
        image = gc.createCompatibleImage((int) component.getSize().getWidth(),
                (int) component.getSize().getHeight());
    } else {
        image = new BufferedImage((int) component.getSize().getWidth(), (int) component.getSize().getHeight(),
                BufferedImage.TYPE_INT_ARGB);
    }

    Graphics g = image.getGraphics();
    if (usePrint) {
        component.print(g);
    } else {
        component.paint(g);
    }
    g.dispose();

    return image;
}