Example usage for java.awt.image BufferedImage getType

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

Introduction

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

Prototype

public int getType() 

Source Link

Document

Returns the image type.

Usage

From source file:VASSAL.tools.image.ImageIOImageLoaderTest.java

@Test
public void testLoad_iTXTBug() throws IOException {
    final String efile = "test/VASSAL/tools/image/no-iTXt.png";
    final String afile = "test/VASSAL/tools/image/iTXt.png";

    final ImageTypeConverter mconv = new MemoryImageTypeConverter();
    final ImageIOImageLoader loader = new ImageIOImageLoader(mconv);

    final BufferedImage expected = read(loader, efile);
    final BufferedImage actual = read(loader, afile);

    assertEquals(BufferedImage.TYPE_INT_ARGB, actual.getType());
    assertImageContentEquals(expected, actual);
}

From source file:VASSAL.tools.image.tilecache.TileUtils.java

/**
 * Write a tile image to a stream.//from   www .  ja  v a2s .com
 *
 * @param tile the image
 * @param out the stream
 *
 * @throws ImageIOException if the write fails
 */
public static void write(BufferedImage tile, OutputStream out) throws IOException {
    ByteBuffer bb;

    // write the header
    bb = ByteBuffer.allocate(18);

    bb.put("VASSAL".getBytes()).putInt(tile.getWidth()).putInt(tile.getHeight()).putInt(tile.getType());

    out.write(bb.array());

    // write the tile data
    final DataBufferInt db = (DataBufferInt) tile.getRaster().getDataBuffer();
    final int[] data = db.getData();

    bb = ByteBuffer.allocate(4 * data.length);
    bb.asIntBuffer().put(data);

    final GZIPOutputStream zout = new GZIPOutputStream(out);
    zout.write(bb.array());
    zout.finish();
}

From source file:zz.pseas.ghost.utils.BrowserUtil.java

public static byte[] captureScreenShotById(WebDriver driver, String id) throws IOException {
    byte[] bytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
    WebElement ele = driver.findElement(By.id(id));
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);

    BufferedImage image = ImgUtil.bytesToBImage(bytes);

    ImageIO.write(image, "jpg", new File("d:/big.jpg"));
    in.close();/*from   ww w .j a va  2s. co  m*/
    System.out.println(image.getType());

    Point p = ele.getLocation();
    Dimension xy = ele.getSize();

    BufferedImage subImage = image.getSubimage(p.getX(), p.getY(), xy.getWidth(), xy.getHeight());
    ImageIO.write(subImage, "jpg", new File("d:/sc.jpg"));
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    ImageIO.write(subImage, "jpg", out);
    out.flush();
    byte[] res = out.toByteArray();
    out.close();
    return res;
}