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

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    BufferedImage bi = new BufferedImage(10, 20, 0);
    Graphics2D g2 = ge.createGraphics(bi);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Image image = new ImageIcon("image.gif").getImage();

    BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);

    Graphics2D g = bimage.createGraphics();
    g.drawImage(image, 0, 0, null);//from w  w w  .  j ava 2 s. com
    g.dispose();
}

From source file:Main.java

public static void main(String[] args) {
    Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    JPanel gui = new JPanel(new BorderLayout());

    JLabel clouds = new JLabel(new ImageIcon(new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB)));
    gui.add(clouds);//  w w  w.  j a va2 s  .com

    JOptionPane.showConfirmDialog(null, gui, "Title", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, new ImageIcon(image));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_USHORT_GRAY);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.WHITE);// w  w  w  . jav a  2  s.  co m
    g2d.fillRect(0, 0, 100, 100);
    g2d.setColor(new Color(255, 123, 0));

    g2d.drawLine(100, 100, 1, 1);

    g2d.dispose();
    BufferedImage scaledImage = new BufferedImage(1000, 1000, BufferedImage.TYPE_USHORT_GRAY);

    Graphics2D graphics2D = scaledImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(bi, 0, 0, 1000, 1000, null);
    graphics2D.dispose();
    ImageIO.write(scaledImage, "png", new File("c:/Java_Dev/Test.png"));
    bi.flush();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bsrc = ImageIO.read(new File("a.jpg"));
    BufferedImage bdest = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bdest.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(2, 2);
    g.drawRenderedImage(bsrc, at);//  w  w  w . j av a2  s  . c o m
    ImageIO.write(bdest, "JPG", new File("b.jpg"));
}

From source file:Main.java

public static void main(String arg[]) throws Exception {

    String yourText = "java2s.com";
    BufferedImage bufferedImage = new BufferedImage(170, 30, BufferedImage.TYPE_INT_RGB);

    Graphics graphics = bufferedImage.getGraphics();
    graphics.setColor(Color.LIGHT_GRAY);
    graphics.fillRect(0, 0, 200, 50);/*from  w w  w .ja v  a2  s . c o m*/
    graphics.setColor(Color.BLACK);
    graphics.setFont(new Font("Arial Black", Font.BOLD, 20));
    graphics.drawString(yourText, 10, 25);

    ImageIO.write(bufferedImage, "jpg", new File("C:/Users/image.jpg"));

    System.out.println("Image Created");
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();
    g.setColor(Color.white);//from w ww  .j a v a2s.  co  m
    g.fillRect(0, 0, 20, 20);
    g.setColor(Color.black);
    g.fillRect(5, 5, 10, 10);

    Color[] mapping = new Color[] { Color.black, Color.white, // replace black with white 
            Color.white, Color.green // and white with green
    };

    ImageIO.write(img, "png", new File("original.png"));
    swapColors(img, mapping);
    ImageIO.write(img, "png", new File("swapped.png"));
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    int width = 100;// width of your image
    int height = 100; // height of your image

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            int grayscale = 123;
            int colorValue = grayscale | grayscale << 8 | grayscale << 16;
            img.setRGB(x, y, colorValue);
        }/*from   w  ww  .j  a  va 2 s .  c  o  m*/
    }
    ImageIO.write(img, "png", new File("c:/Java_Dev/output.png"));
}

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 w  w.  j  a  v a  2s.  c o  m
    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"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorConvertOp op = new ColorConvertOp(cs, null);

    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);
    bufferedImage = op.filter(bufferedImage, null);
}