當前位置: 首頁>>代碼示例>>Java>>正文


Java PixelGrabber類代碼示例

本文整理匯總了Java中java.awt.image.PixelGrabber的典型用法代碼示例。如果您正苦於以下問題:Java PixelGrabber類的具體用法?Java PixelGrabber怎麽用?Java PixelGrabber使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PixelGrabber類屬於java.awt.image包,在下文中一共展示了PixelGrabber類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTransparency

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * Gets the transparency of an image.
 *
 * @param image the image
 * @return OPAQUE, BITMASK or TRANSLUCENT (see java.awt.Transparency)
 */
public static int getTransparency( Image image ) {
    // If buffered image, the color model is readily available
    if ( image instanceof BufferedImage ) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().getTransparency();
    }
    // 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();

    int transparency = Transparency.OPAQUE;
    if ( cm != null ) {
        transparency = cm.getTransparency();
    }
    return transparency;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:31,代碼來源:BufferedImageUtils.java

示例2: getGTKProfilerResultsBackground

import java.awt.image.PixelGrabber; //導入依賴的package包/類
private static Color getGTKProfilerResultsBackground() {
    int[] pixels = new int[1];
    pixels[0] = -1;
    
    // Prepare textarea to grab the color from
    JTextArea textArea = new JTextArea();
    textArea.setSize(new Dimension(10, 10));
    textArea.doLayout();
    
    // Print the textarea to an image
    Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB);
    textArea.printAll(image.getGraphics());
    
    // Grab appropriate pixels to get the color
    PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1);
    try {
        pixelGrabber.grabPixels();
        if (pixels[0] == -1) return Color.WHITE; // System background not customized
    } catch (InterruptedException e) {
        return getNonGTKProfilerResultsBackground();
    }
    
    return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:UIUtils.java

示例3: getOffscreenEquivalent

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * For the given input color, return the color that this color
 * will map to in an offscreen image created by the given Component
 */
public static int getOffscreenEquivalent(int color, Component obs) {
  Image im = obs.createImage(1, 1);
  Graphics2D g = (Graphics2D) im.getGraphics();
  g.setColor(new java.awt.Color(color));
  g.fillRect(0, 0, 1, 1);
  g.dispose();

  int[] bg = new int[1];
  PixelGrabber pg = new PixelGrabber(im, 0, 0, 1, 1, bg, 0, 1);
  try {
    pg.grabPixels();
  }
  catch (InterruptedException ex) {
    logger.error("", ex);
  }
  return bg[0];
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:22,代碼來源:TransparentFilter.java

示例4: hasAlpha

import java.awt.image.PixelGrabber; //導入依賴的package包/類
public static boolean hasAlpha(Image image) {
	
	if (image instanceof BufferedImage)
		return ((BufferedImage)image).getColorModel().hasAlpha();
	
	PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
	
	try {
		pg.grabPixels();
	}
	
	catch (InterruptedException e)
	{
	}
	
	return pg.getColorModel().hasAlpha();
}
 
開發者ID:Library-of-Kaeon,項目名稱:Library-of-Kaeon,代碼行數:18,代碼來源:ImageProcessor.java

示例5: bressed

import java.awt.image.PixelGrabber; //導入依賴的package包/類
static private Image bressed(final Image image) {
    final int i = image.getHeight(null);
    final int i340 = image.getWidth(null);
    final int[] is = new int[i340 * i];
    final PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, i340, i, is, 0, i340);
    try {
        pixelgrabber.grabPixels();
    } catch (final InterruptedException ignored) {

    }
    final Color color = new Color(247, 255, 165);
    for (int i341 = 0; i341 < i340 * i; i341++)
        if (is[i341] != is[i340 * i - 1]) {
            is[i341] = color.getRGB();
        }
    return xt.createImage(new MemoryImageSource(i340, i, is, 0, i340));
}
 
開發者ID:uwx,項目名稱:OpenNFMM,代碼行數:18,代碼來源:xtGraphics.java

示例6: pressed

import java.awt.image.PixelGrabber; //導入依賴的package包/類
static private Image pressed(final Image image) {
    final int i = image.getHeight(null);
    final int i337 = image.getWidth(null);
    final int[] is = new int[i337 * i];
    final PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, i337, i, is, 0, i337);
    try {
        pixelgrabber.grabPixels();
    } catch (final InterruptedException ignored) {

    }
    for (int i338 = 0; i338 < i337 * i; i338++)
        if (is[i338] != is[i337 * i - 1]) {
            is[i338] = -16777216;
        }
    return xt.createImage(new MemoryImageSource(i337, i, is, 0, i337));
}
 
開發者ID:uwx,項目名稱:OpenNFMM,代碼行數:17,代碼來源:xtGraphics.java

示例7: hasAlpha

import java.awt.image.PixelGrabber; //導入依賴的package包/類
public 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();
    }

    // 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();
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:BufferedImageUtils.java

示例8: getImageToWrite

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * Get the image to write. This is the mosaic image with alpha channel stripped, as this
 * doesn't work with the JPEG export.
 */
private BufferedImage getImageToWrite() throws InterruptedException {
	BufferedImage image = SwingFXUtils.fromFXImage(mainController.getMosaicImage(), null);
	final int[] RGB_MASKS = {0xFF0000, 0xFF00, 0xFF};
	final ColorModel rgbOpaque = new DirectColorModel(32, RGB_MASKS[0], RGB_MASKS[1], RGB_MASKS[2]);

	PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true);
	pg.grabPixels();
	int width = pg.getWidth(), height = pg.getHeight();

	DataBuffer buffer = new DataBufferInt((int[]) pg.getPixels(), pg.getWidth() * pg.getHeight());
	WritableRaster raster = Raster.createPackedRaster(buffer, width, height, width, RGB_MASKS, null);
	BufferedImage bi = new BufferedImage(rgbOpaque, raster, false, null);
	
	return bi;
}
 
開發者ID:mrpolyonymous,項目名稱:BrickifyFX,代碼行數:20,代碼來源:OutputPaneController.java

示例9: convertImage

import java.awt.image.PixelGrabber; //導入依賴的package包/類
private boolean convertImage(Image parImage, int parWidth, int parHeight) {
	int pad;
	bitmap = new int[parWidth * parHeight];
	final PixelGrabber pg = new PixelGrabber(parImage, 0, 0, parWidth, parHeight, bitmap, 0, parWidth);
	try {
		pg.grabPixels();
	} catch (final InterruptedException e) {
		e.printStackTrace();
		return (false);
	}
	pad = (4 - ((parWidth * 3) % 4)) * parHeight;
	biSizeImage = ((parWidth * parHeight) * 3) + pad;
	bfSize = biSizeImage + BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
	biWidth = parWidth;
	biHeight = parHeight;
	return (true);
}
 
開發者ID:XDrake99,項目名稱:WarpPI,代碼行數:18,代碼來源:BMPFile.java

示例10: getTransparency

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * Returns the transparency. Returns either OPAQUE, BITMASK, or TRANSLUCENT.
 *
 * @param image
 *            The image.
 * @return the transparency of this ColorModel.
 */
private int getTransparency(Image image) {
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        return bimage.getColorModel().getTransparency();
    }
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        if (pg.grabPixels() && pg.getColorModel() != null) {
            return pg.getColorModel().getTransparency();
        }
    } catch (InterruptedException e) {
        LOGGER.warn(e.getMessage());
    }
    // fallback to generic type
    return Transparency.TRANSLUCENT;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:24,代碼來源:ImageScaler.java

示例11: grabPixels

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * Use a PixelGrabber to grab the pixel data from the camera stream.
 *
 */
public void grabPixels ( ) {
	
	// Get the width and height of the camera image.
	int width = this.cameraStream.getWidth( this );
	int height = this.cameraStream.getHeight( this );
	
	// Create a new pixels array with a given width and height.
	this.pixels = new int[ width * height ];
	
	// Create a new PixelGrabber using the camera stream and place the grabbed
	// pixel data into this.pixels.
	this.grabber = new PixelGrabber( this.cameraStream, 0, 0, width, height, this.pixels, 0, width );     

	try {
		
		// Grab the pixels.
		this.grabber.grabPixels( );
		
	}
	catch ( Exception e ) {
		log.error("Failed to grab pixels.", e);
	} // end catch

}
 
開發者ID:markkolich,項目名稱:axisviewer,代碼行數:29,代碼來源:Camera.java

示例12: Sprite

import java.awt.image.PixelGrabber; //導入依賴的package包/類
public Sprite(byte abyte0[], Component component) {
	try {
		Image image = Toolkit.getDefaultToolkit().createImage(abyte0);
		MediaTracker mediatracker = new MediaTracker(component);
		mediatracker.addImage(image, 0);
		mediatracker.waitForAll();
		myWidth = image.getWidth(component);
		myHeight = image.getHeight(component);
		anInt1444 = myWidth;
		anInt1445 = myHeight;
		drawOffsetX = 0;
		drawOffsetY = 0;
		myPixels = new int[myWidth * myHeight];
		PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
		pixelgrabber.grabPixels();
	} catch (Exception _ex) {
		System.out.println("Error converting jpg");
	}
}
 
開發者ID:Jarinus,項目名稱:osrs-private-server,代碼行數:20,代碼來源:Sprite.java

示例13: getColorAt

import java.awt.image.PixelGrabber; //導入依賴的package包/類
@Nullable
public static Color getColorAt(final Icon icon, final int x, final int y) {
  if (0 <= x && x < icon.getIconWidth() && 0 <= y && y < icon.getIconHeight()) {
    final BufferedImage image = createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    icon.paintIcon(null, image.getGraphics(), 0, 0);

    final int[] pixels = new int[1];
    final PixelGrabber pixelGrabber = new PixelGrabber(image, x, y, 1, 1, pixels, 0, 1);
    try {
      pixelGrabber.grabPixels();
      return new Color(pixels[0]);
    }
    catch (InterruptedException ignored) {
    }
  }

  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:UIUtil.java

示例14: hasAlpha

import java.awt.image.PixelGrabber; //導入依賴的package包/類
public 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();
	}

	// 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();
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:20,代碼來源:Util.java

示例15: hasAlpha

import java.awt.image.PixelGrabber; //導入依賴的package包/類
/**
 * The next two mehtds where got from http://javaalmanac
 * .com/egs/java.awt.image/HasAlpha.html T
 * 
 * @param image
 * @return
 */
// This method returns true if the specified
// image has transparent pixels
public 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();
	}

	// 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();
}
 
開發者ID:TOMIGalway,項目名稱:cmoct-sourcecode,代碼行數:32,代碼來源:ImageOperations.java


注:本文中的java.awt.image.PixelGrabber類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。