List of usage examples for java.awt.image SinglePixelPackedSampleModel SinglePixelPackedSampleModel
public SinglePixelPackedSampleModel(int dataType, int w, int h, int[] bitMasks)
From source file:GrabandFadewithRasters.java
public void init() { URL url;/*ww w. j a v a 2 s . c o m*/ try { url = new URL(imageURLString); originalImage = getImage(url); } catch (MalformedURLException me) { showStatus("Malformed URL: " + me.getMessage()); } try { PixelGrabber grabber = new PixelGrabber(originalImage, 0, 0, -1, -1, true); if (grabber.grabPixels()) { width = grabber.getWidth(); height = grabber.getHeight(); originalPixelArray = (int[]) grabber.getPixels(); mis = new MemoryImageSource(width, height, originalPixelArray, 0, width); mis.setAnimated(true); newImage = createImage(mis); } else { System.err.println("Grabbing Failed"); } } catch (InterruptedException ie) { System.err.println("Pixel Grabbing Interrupted"); } DataBufferInt dbi = new DataBufferInt(originalPixelArray, width * height); int bandmasks[] = { 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff }; SampleModel sm; sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, width, height, bandmasks); raster = Raster.createWritableRaster(sm, dbi, null); }
From source file:lucee.runtime.img.Image.java
private BufferedImage jpgImage(BufferedImage src) { int w = src.getWidth(); int h = src.getHeight(); SampleModel srcSM = src.getSampleModel(); WritableRaster srcWR = src.getRaster(); java.awt.image.DataBuffer srcDB = srcWR.getDataBuffer(); ColorModel rgb = new DirectColorModel(32, 0xff0000, 65280, 255); int[] bitMasks = new int[] { 0xff0000, 65280, 255 }; SampleModel csm = new SinglePixelPackedSampleModel(3, w, h, bitMasks); int data[] = new int[w * h]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int pix[] = null; int sample[] = srcSM.getPixel(j, i, pix, srcDB); if (sample[3] == 0 && sample[2] == 0 && sample[1] == 0 && sample[0] == 0) data[i * w + j] = 0xffffff; else/*from w w w. j ava 2 s . co m*/ data[i * w + j] = sample[0] << 16 | sample[1] << 8 | sample[2]; } } java.awt.image.DataBuffer db = new DataBufferInt(data, w * h * 3); WritableRaster wr = Raster.createWritableRaster(csm, db, new Point(0, 0)); return new BufferedImage(rgb, wr, false, null); }