List of usage examples for java.awt.image DataBuffer setElem
public void setElem(int i, int val)
From source file:omr.jai.TestImage3.java
public static PlanarImage decodeImage (String[] rows) {//www . j a va 2s .c o m // Create the DataBuffer to hold the pixel samples final int width = rows[0].length(); final int height = rows.length; // Create Raster Raster raster; if (true) { raster = Raster.createPackedRaster (DataBuffer.TYPE_INT, width, height, new int[] {0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},// bandMasks RGBA null); } else { raster = Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE, width, height, 4,// num of bands null); } // Populate the data buffer DataBuffer dataBuffer = raster.getDataBuffer(); int index = 0; for (String row : rows) { for (int x = 0; x < width; x++) { int argb = toARGB(row.charAt(x)); dataBuffer.setElem(index, argb); index++; } } // Dump // final int size = width * height; // System.out.println("DataBuffer :"); // for (int i = 0; i < size; i++) { // if (i % width == 0) { // System.out.println(); // } // System.out.print(String.format("%8x ", dataBuffer.getElem(i))); // } // System.out.println(); // Create the image BufferedImage bufferedImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB); bufferedImage.setData(raster); // Dump // System.out.println("BufferedImage :"); // for (int y = 0; y < height; y++) { // System.out.println(); // for (int x = 0; x < width; x++) { // System.out.print(String.format("%8x ", bufferedImage.getRGB(x, y))); // } // } // System.out.println(); return PlanarImage.wrapRenderedImage(bufferedImage); }
From source file:RasterDemo.java
public void flipBufferedImage() { bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(), bi1.getType()); DataBuffer db1 = bi1.getRaster().getDataBuffer(); DataBuffer db2 = bi2.getRaster().getDataBuffer(); for (int i = db1.getSize() - 1, j = 0; i >= 0; --i, j++) { db2.setElem(j, db1.getElem(i)); }// w ww .java 2 s . c o m }