List of usage examples for java.awt.image Raster createPackedRaster
public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h, int bitsPerPixel, Point location)
From source file:StaticGenerator.java
public void initialize() { int w = getSize().width, h = getSize().height; int length = ((w + 7) * h) / 8; data = new byte[length]; DataBuffer db = new DataBufferByte(data, length); WritableRaster wr = Raster.createPackedRaster(db, w, h, 1, null); ColorModel cm = new IndexColorModel(1, 2, new byte[] { (byte) 0, (byte) 255 }, new byte[] { (byte) 0, (byte) 255 }, new byte[] { (byte) 0, (byte) 255 }); image = new BufferedImage(cm, wr, false, null); random = new Random(); new Thread(this).start(); }
From source file:omr.jai.TestImage3.java
public static PlanarImage decodeImage (String[] rows) {//from ww w. j a v a2s . 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:PNGDecoder.java
public WritableRaster getRaster() { int width = (int) getWidth(); int height = (int) getHeight(); int bitsPerPixel = getBitsPerPixel(); short colorType = getColorType(); if (colorType == 3) { byte[] imageData = getImageData(); DataBuffer db = new DataBufferByte(imageData, imageData.length); WritableRaster raster = Raster.createPackedRaster(db, width, height, bitsPerPixel, null); return raster; } else//from www . j a v a2 s . co m System.out.println("Unsupported color type!"); return null; }
From source file:c.depthchart.ViewerPanel.java
public void paintComponent(Graphics g) // Draw the depth image and statistics info { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // convert image pixel array into an image DataBufferByte dataBuffer = new DataBufferByte(imgbytes, imWidth * imHeight); Raster raster = Raster.createPackedRaster(dataBuffer, imWidth, imHeight, 8, null); image.setData(raster);/*ww w. j a v a 2 s . c o m*/ if (image != null) g2.drawImage(image, 0, 0, this); writeStats(g2); }
From source file:MyJava3D.java
private BufferedImage createBinaryImage(int w, int h, int pixelBits) { int[] pixels = new int[w * h]; int bytesPerRow = w * pixelBits / 8; if (w * pixelBits % 8 != 0) { bytesPerRow++;/* ww w .java 2 s. co m*/ } byte[] imageData = new byte[h * bytesPerRow]; IndexColorModel cm = null; switch (pixelBits) { case 1: cm = new IndexColorModel(pixelBits, lut1Arr.length, lut1Arr, lut1Arr, lut1Arr); break; case 2: cm = new IndexColorModel(pixelBits, lut2Arr.length, lut2Arr, lut2Arr, lut2Arr); break; case 4: cm = new IndexColorModel(pixelBits, lut4Arr.length, lut4Arr, lut4Arr, lut4Arr); break; default: { new Exception("Invalid # of bit per pixel").printStackTrace(); } } DataBuffer db = new DataBufferByte(imageData, imageData.length); WritableRaster r = Raster.createPackedRaster(db, w, h, pixelBits, null); return new BufferedImage(cm, r, false, null); }
From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java
private WritableRaster createRaster(final int width, final int height, final int bands, final int scanlineStride, final int bitDepth) { DataBuffer dataBuffer;/*from w w w . j ava 2 s. c o m*/ WritableRaster ras = null; final Point origin = new Point(0, 0); if (bitDepth < 8 && bands == 1) { dataBuffer = new DataBufferByte(height * scanlineStride); ras = Raster.createPackedRaster(dataBuffer, width, height, bitDepth, origin); } else if (bitDepth <= 8) { dataBuffer = new DataBufferByte(height * scanlineStride); ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, this.bandOffsets[bands], origin); } else { dataBuffer = new DataBufferUShort(height * scanlineStride); ras = Raster.createInterleavedRaster(dataBuffer, width, height, scanlineStride, bands, this.bandOffsets[bands], origin); } return ras; }
From source file:org.kuali.kra.printing.service.impl.PersonSignatureServiceImpl.java
/** * This method is to get buffered image based on predefined parameters * @param params//w ww . j a v a 2 s. c om * @param imageData * @return */ protected BufferedImage getBufferedImage(ImageParameters params, byte[] imageData) { byte[] transparentColors = new byte[] { (byte) 0xFF, (byte) 0xFF }; byte[] colors = new byte[] { 0, (byte) 0xFF }; IndexColorModel colorModel = new IndexColorModel(1, 2, colors, colors, colors, transparentColors); BufferedImage image = new BufferedImage(params.getWidth(), params.getHeight(), BufferedImage.TYPE_BYTE_BINARY, colorModel); DataBufferByte buffer = new DataBufferByte(imageData, 1); WritableRaster raster = Raster.createPackedRaster(buffer, params.getWidth(), params.getHeight(), params.getBitsPerComponent(), new Point(0, 0)); image.setData(raster); return image; }