本文整理汇总了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;
}
示例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();
}
示例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];
}
示例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();
}
示例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));
}
示例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));
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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
}
示例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");
}
}
示例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;
}
示例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();
}
示例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();
}