List of usage examples for java.awt.image PixelGrabber getHeight
public synchronized int getHeight()
From source file:Main.java
public static void main(String args[]) throws Exception { Image image = Toolkit.getDefaultToolkit().getImage("inFile.png"); PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false); if (grabber.grabPixels()) { int width = grabber.getWidth(); int height = grabber.getHeight(); if (isGreyscaleImage(grabber)) { byte[] data = (byte[]) grabber.getPixels(); } else {//from w ww. ja v a 2 s . c om int[] data = (int[]) grabber.getPixels(); } } }
From source file:com.xebia.visualreview.PixelComparator.java
public static DiffReport processImage(File beforeFile, File afterFile, java.util.Map maskInfo, String compareSettings) { try {// ww w. j a v a2 s . c o m int precision = getPrecision(compareSettings); PixelGrabber beforeGrab = grabImage(beforeFile); PixelGrabber afterGrab = grabImage(afterFile); int[] beforeData = null; int[] afterData = null; int beforeWidth = 0; int afterWidth = 0; int y1 = 0; int y2 = 0; if (beforeGrab.grabPixels()) { beforeWidth = beforeGrab.getWidth(); y1 = beforeGrab.getHeight(); beforeData = (int[]) beforeGrab.getPixels(); } if (afterGrab.grabPixels()) { afterWidth = afterGrab.getWidth(); y2 = afterGrab.getHeight(); afterData = (int[]) afterGrab.getPixels(); } int minX = Math.min(beforeWidth, afterWidth); int minY = Math.min(y1, y2); int diffWidth = Math.max(beforeWidth, afterWidth); int diffHeight = Math.max(y1, y2); int[] diffData = new int[diffWidth * diffHeight]; int differentPixels = 0; boolean hasMask = (maskInfo != null); BufferedImage maskImage = generateMask(maskInfo, diffWidth, diffHeight); for (int y = 0; y < diffHeight; y++) { for (int x = 0; x < diffWidth; x++) { if (maskImage.getRGB(x, y) != DIFFCOLOUR) { if (x >= minX || y >= minY || hasDifference(beforeData[y * beforeWidth + x], afterData[y * afterWidth + x], precision)) { diffData[y * diffWidth + x] = DIFFCOLOUR; differentPixels++; } } } } BufferedImage diffImage = new BufferedImage(diffWidth, diffHeight, BufferedImage.TYPE_INT_ARGB); diffImage.setRGB(0, 0, diffWidth, diffHeight, diffData, 0, diffWidth); DiffReport report = new DiffReport(beforeFile, afterFile, diffImage, differentPixels); if (hasMask) { report.setMaskImage(maskImage); } return report; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:GrabandFadewithRasters.java
public void init() { URL url;/*from www. j a v a2s. com*/ 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:GrabandFade.java
public void init() { URL url;//from w w w . jav a 2s. c om try { // set imageURLString here url = new URL(imageURLString); originalImage = getImage(url); } catch (MalformedURLException me) { showStatus("Malformed URL: " + me.getMessage()); } /* * Create PixelGrabber and use it to fill originalPixelArray with image * pixel data. This array will then by used by the MemoryImageSource. */ 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"); } }