List of usage examples for java.awt.image PixelGrabber PixelGrabber
public PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)
From source file:org.wings.SImageIcon.java
protected static String determineMimeType(ImageIcon imageIcon) { String mimeType = extractMimeTypeFromPath(imageIcon.getDescription()); if (mimeType != null) return mimeType; PixelGrabber pg = new PixelGrabber(imageIcon.getImage(), 0, 0, 1, 1, false); try {//w ww .j a v a 2s . c o m pg.grabPixels(); } catch (InterruptedException e) { log.warn("interrupted waiting for pixels!"); } mimeType = "image/"; if (!(pg.getColorModel() instanceof IndexColorModel)) mimeType += ImageExternalizer.FORMAT_PNG; else mimeType += ImageExternalizer.FORMAT_GIF; return mimeType; }
From source file:de.laures.cewolf.util.ImageHelper.java
public static boolean hasAlpha(Image image) { if (image instanceof BufferedImage) { return ((BufferedImage) image).getColorModel().hasAlpha(); }/* w w w . jav a 2 s. c om*/ PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } ColorModel cm = pg.getColorModel(); if (cm == null) { return false; } return cm.hasAlpha(); }
From source file:com.jaeksoft.searchlib.util.ImageUtils.java
public static boolean hasAlpha(Image image) throws InterruptedException { if (image instanceof BufferedImage) return ((BufferedImage) image).getColorModel().hasAlpha(); PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); pg.grabPixels();// w w w . j a v a 2s. c o m return pg.getColorModel().hasAlpha(); }
From source file:GifEncoder.java
/** Constructs a new GifEncoder using an 8-bit AWT Image. The image is assumed to be fully loaded. */ public GifEncoder(Image img) { width = img.getWidth(null);//w w w. j av a2s. c o m height = img.getHeight(null); pixels = new byte[width * height]; PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, false); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println(e); } ColorModel cm = pg.getColorModel(); if (cm instanceof IndexColorModel) { pixels = (byte[]) (pg.getPixels()); // hpm IndexColorModel icm = (IndexColorModel) cm; setTransparentPixel(icm.getTransparentPixel()); } else throw new IllegalArgumentException("IMAGE_ERROR"); IndexColorModel m = (IndexColorModel) cm; int mapSize = m.getMapSize(); r = new byte[mapSize]; g = new byte[mapSize]; b = new byte[mapSize]; m.getReds(r); m.getGreens(g); m.getBlues(b); interlace = false; pixelIndex = 0; numPixels = width * height; }
From source file:FontAlgo.java
private static TextualChar getTextualChar(char a_char) throws Throwable { BufferedImage bImg = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics g = bImg.getGraphics(); g.setColor(Color.green);// w w w. j a v a2 s . co m g.fillRect(0, 0, WIDTH, HEIGHT); g.setFont(appliedFont); g.setColor(Color.black); g.drawString(new String(new char[] { a_char }), 10, g.getFontMetrics().getHeight()); PixelGrabber p = new PixelGrabber(bImg, 0, 0, WIDTH, HEIGHT, true); if (p.grabPixels()) { char[][] pattern = new char[WIDTH][HEIGHT]; int baseColourPixel = 0, contrastColourPixel = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0; int[] pixels = (int[]) p.getPixels(); baseColourPixel = pixels[0]; // System.out.println("base: " + base); int xCounter = 0, yCounter = 0; for (int iPixel : pixels) { // System.out.println(iX + " - " + iY); if (isReverse) { pattern[xCounter][yCounter] = iPixel == baseColourPixel ? CHAR_TO_PATTERN : ' '; } else { pattern[xCounter][yCounter] = iPixel != baseColourPixel ? CHAR_TO_PATTERN : ' '; } yCounter++; if (yCounter > 49) { xCounter++; yCounter = 0; } if (contrastColourPixel == 0 && iPixel != baseColourPixel) { contrastColourPixel = iPixel; x1 = xCounter - 2; y1 = yCounter - 3; y2 = yCounter + 3; } if (contrastColourPixel == iPixel) { x2 = xCounter + 3; if (y1 > (yCounter - 3)) { y1 = yCounter - 3; } if (y2 < (yCounter + 3)) { y2 = yCounter + 3; } } } return new TextualChar(x1, x2, y1, y2, pattern); } return null; }
From source file:ro.nextreports.designer.util.ImageUtil.java
private static boolean hasAlpha(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { BufferedImage bimage = (BufferedImage) image; return bimage.getColorModel().hasAlpha(); }//from w w w . j ava2 s. co m // Use a pixel grabber to retrieve the image's color model; // grabbing a single pixel is usually sufficient PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } // Get the image's color model ColorModel cm = pg.getColorModel(); return cm.hasAlpha(); }
From source file:com.xebia.visualreview.PixelComparator.java
private static PixelGrabber grabImage(File file) { try {/* www . java 2 s . c o m*/ return new PixelGrabber(loadImage(file), 0, 0, -1, -1, true); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:ImageUtils.java
/** * Determines if the image has transparent pixels. * /*from w w w . ja v a2 s .co m*/ * @param image The image to check for transparent pixel.s * @return <code>true</code> of <code>false</code>, according to the result */ public static boolean hasAlpha(Image image) { try { PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); pg.grabPixels(); return pg.getColorModel().hasAlpha(); } catch (InterruptedException e) { return false; } }
From source file:org.yccheok.jstock.gui.Utils.java
private static boolean hasAlpha(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { BufferedImage bimage = (BufferedImage) image; return bimage.getColorModel().hasAlpha(); }/* w ww. j a v a 2 s . c o m*/ // Use a pixel grabber to retrieve the image's color model; // grabbing a single pixel is usually sufficient PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { } // Get the image's color model ColorModel cm = pg.getColorModel(); return cm.hasAlpha(); }
From source file:com.aurel.track.attachment.AttachBL.java
private static boolean hasAlpha(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { BufferedImage bimage = (BufferedImage) image; return bimage.getColorModel().hasAlpha(); }//from ww w. jav a 2 s . c o m // grabbing a single pixel is usually sufficient PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { } // Get the image's color model ColorModel cm = pg.getColorModel(); return cm.hasAlpha(); }