Example usage for java.awt.image BufferedImage TYPE_INT_RGB

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

Introduction

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

Prototype

int TYPE_INT_RGB

To view the source code for java.awt.image BufferedImage TYPE_INT_RGB.

Click Source Link

Document

Represents an image with 8-bit RGB color components packed into integer pixels.

Usage

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. jav  a  2  s  .  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[] args) throws Exception {
    BufferedImage bufferedImage = ImageIO.read(new File("a.jpg"));
    BufferedImage destinationBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = destinationBufferedImage.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(2, 2);
    g.drawRenderedImage(bufferedImage, at);
    ImageIO.write(destinationBufferedImage, "JPG", new File("b.jpg"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bi;/*ww w .jav a2 s.c  o  m*/
    bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    for (int i = 0; i < NUM_ITER; i++) {
        g.setColor(Color.RED);
        g.drawLine(1, 2, i, i + 1);
    }
    g.dispose();
    ImageIO.write(bi, "gif", new File("image.gif"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int width = 100;
    int height = 100;

    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = bufferedImage.createGraphics();

    g2d.setColor(Color.white);// ww w  .ja v a 2s  .c o  m
    g2d.fillRect(0, 0, width, height);
    g2d.setColor(Color.black);
    g2d.fillOval(0, 0, width, height);

    g2d.dispose();
    RenderedImage rendImage = bufferedImage;

    File file = new File("newimage.png");
    ImageIO.write(rendImage, "png", file);

    file = new File("newimage.jpg");
    ImageIO.write(rendImage, "jpg", file);
}

From source file:Main.java

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

    BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_RGB);

    Graphics g = bufferedImage.createGraphics();
    g.drawImage(img, 0, 0, null);/*from ww  w.  j  ava 2s.  c o m*/
    g.dispose();

    ImageIO.write(bufferedImage, "png", new File("a.png"));
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(2, 2));
    BufferedImage bi = new BufferedImage(600, 200, BufferedImage.TYPE_INT_RGB);
    gui.add(new JLabel(new ImageIcon(bi)));

    JFrame myframe = new JFrame();
    JPanel myPanel = new JPanel();
    gui.add(myPanel, BorderLayout.PAGE_END);
    myPanel.setLayout(new GridLayout(2, 0, 0, 0));

    int x = 0;/*from  w  w w.ja  va2  s .co  m*/
    int y = 5;

    for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
        myPanel.add(new JButton(alphabet + ""));
        x++;
        if (x > 15) {
            y = 6;
            x = 0;
        }
    }
    myframe.add(gui);
    myframe.pack();
    myframe.setVisible(true);

    myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    String s = "The quick brown fox jumps over the lazy dog!";
    BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    Rectangle2D b = fm.getStringBounds(s, g);
    System.out.println(b);//from ww w.j  a v  a 2s  .  co m
    bi = new BufferedImage((int) b.getWidth(), (int) (b.getHeight() + fm.getDescent()),
            BufferedImage.TYPE_INT_RGB);
    g = bi.getGraphics();
    g.drawString(s, 0, (int) b.getHeight());

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi)));

    // Technique 3 - JLabel
    JLabel l = new JLabel(s);
    l.setSize(l.getPreferredSize());
    bi = new BufferedImage(l.getWidth(), l.getHeight(), BufferedImage.TYPE_INT_RGB);
    g = bi.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 400, 100);
    l.paint(g);

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi)));
}

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  ww . j  a va 2 s  .c om

    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 img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);

    Graphics g = img.getGraphics();
    g.setColor(Color.red);/*from  w  ww  .j a  v  a2s  .c  o  m*/
    g.setFont(new Font("Arial", Font.BOLD, 14));
    g.drawString("Reference", 10, 80);

    int w = 100;
    int h = 100;
    int x = 1;
    int y = 1;

    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);

    pg.grabPixels();
    BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            bimg.setRGB(x + i, y + j, pixels[j * w + i]);
        }
    }

    FileOutputStream fout = new FileOutputStream("jpg.jpg");

    JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout);
    JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(bimg);

    enParam.setQuality(1.0F, true);
    jencoder.setJPEGEncodeParam(enParam);
    jencoder.encode(bimg);

    fout.close();

}

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);/*from w ww .  ja v a  2s  . 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);
}