Example usage for java.awt.image BufferedImage getWidth

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

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Returns the width of the BufferedImage .

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    byte[] picture = new byte[2048]; // your image data

    InputStream in = new ByteArrayInputStream(picture);

    BufferedImage buf = ImageIO.read(in);
    ColorModel model = buf.getColorModel();
    int height = buf.getHeight();
    int width = buf.getWidth();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    System.out.println(image == null);
    int width = image.getWidth();
    int height = image.getHeight();
    System.out.println(width + "x" + height);
    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            System.out.printf("%04X ", image.getRGB(col, row));
        }//w  w w .  j a  va 2s. com
        System.out.println();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);

    AffineTransform tx = new AffineTransform();
    tx.rotate(0.5, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2);

    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
    bufferedImage = op.filter(bufferedImage, null);

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage large = ImageIO.read(new File("images/a.jpg"));
    BufferedImage small = ImageIO.read(new File("images/b.jpg"));

    int w = large.getWidth();
    int h = large.getHeight();
    int type = BufferedImage.TYPE_INT_RGB;

    BufferedImage image = new BufferedImage(w, h, type);
    Graphics2D g2 = image.createGraphics();
    g2.drawImage(large, 0, 0, null);// w  w  w. j  av  a  2  s.co  m
    g2.drawImage(small, 10, 10, null);
    g2.dispose();
    ImageIO.write(image, "jpg", new File("new.jpg"));

    JOptionPane.showMessageDialog(null, new ImageIcon(image), "", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) throws java.io.IOException {
    BufferedImage img = ImageIO.read(new File("input-image.png"));

    BufferedImage rotated = new AffineTransformOp(
            AffineTransform.getQuadrantRotateInstance(3, img.getWidth() / 2, img.getHeight() / 2),
            AffineTransformOp.TYPE_BILINEAR).filter(img, null);

    ImageIO.write(rotated, "PNG", new File("output-image.png"));
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage image = ImageIO.read(new File("E:/Java_Dev/plasma.gif"));

    // crop image
    BufferedImage firstHalf = image.getSubimage(0, 0, (image.getWidth() / 2), image.getHeight());
    BufferedImage secondHalf = image.getSubimage(image.getWidth() / 2, 0, image.getWidth() / 2,
            image.getHeight());//from  w  w w. j  av a  2s.c o  m

    File croppedFile1 = new File("E:/Java_Dev/half1.png");
    File croppedFile2 = new File("E:/Java_Dev/half2.png");

    ImageIO.write(firstHalf, "png", croppedFile1);
    ImageIO.write(secondHalf, "png", croppedFile2);

    // join image
    BufferedImage joined = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
    BufferedImage image1 = ImageIO.read(new File("E:/Java_Dev/half1.png"));
    BufferedImage image2 = ImageIO.read(new File("E:/Java_Dev/half2.png"));

    Graphics2D graph = joined.createGraphics();
    graph.drawImage(image1, 0, 0, null);
    graph.drawImage(image2, image1.getWidth(), 0, null);

    File joinedFile = new File("E:/Java_Dev/joined.png");
    ImageIO.write(joined, "png", joinedFile);
}

From source file:SaveIt.java

public static void main(String args[]) throws IOException {
    // Read/*from   w  w w  . ja  va2 s  . c o m*/
    File inputFile = new File("java2s.jpg");
    BufferedImage input = ImageIO.read(inputFile);
    // Convert
    Kernel kernel = new Kernel(3, 3, SHARP);
    ConvolveOp convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    int width = input.getWidth();
    int height = input.getHeight();
    BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    convolveOp.filter(input, output);
    // Save
    File outputFile = new File("java2s.png");
    ImageIO.write(output, "PNG", outputFile);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage bi = ImageIO.read(url);
    SwingUtilities.invokeLater(new Runnable() {
        @Override/* w  w  w.  j  a va  2s .  c  o m*/
        public void run() {
            int strokeWidth = 12;
            int pad = 50;
            Shape shape = new Rectangle(pad, pad, bi.getWidth() - (2 * pad), bi.getHeight() - (2 * pad));
            Image i = getStrokedImage(bi, shape, strokeWidth);
            JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(i)));
        }
    });
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im = ImageIO.read(url);
    URL url2 = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im2 = ImageIO.read(url2);
    Graphics2D g = im.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    g.drawImage(im2, (im.getWidth() - im2.getWidth()) / 2, (im.getHeight() - im2.getHeight()) / 2, null);
    g.dispose();/* w ww.j  a  v a2 s  .  c o  m*/

    display(im);
    ImageIO.write(im, "jpeg", new File("output.jpeg"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int size = 120;
    int pad = 10;
    BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.createGraphics();
    g.setColor(Color.WHITE);/*from   w  ww  . jav a 2s . c  om*/
    g.fillRect(0, 0, size, size);
    g.setColor(Color.YELLOW);
    g.fillOval(pad, pad, size - (2 * pad), size - (2 * pad));
    g.dispose();

    BufferedImage image2 = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_BYTE_GRAY);

    ColorConvertOp op = new ColorConvertOp(bi.getColorModel().getColorSpace(),
            image2.getColorModel().getColorSpace(), null);
    op.filter(bi, image2);
    ImageIO.write(image2, "png", new File("c:/Java_Dev/image2.png"));
}