当前位置: 首页>>代码示例>>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;未经允许,请勿转载。