/**
* 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;
}
java类java.awt.image.PixelGrabber的实例源码
BufferedImageUtils.java 文件源码
项目:PhET
阅读 23
收藏 0
点赞 0
评论 0
UIUtils.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
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();
}
TransparentFilter.java 文件源码
项目:VASSAL-src
阅读 24
收藏 0
点赞 0
评论 0
/**
* 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];
}
TabUtilities.java 文件源码
项目:myster
阅读 25
收藏 0
点赞 0
评论 0
public static int[] getPixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h]; // PixelGrabber does the work of getting
// actual RGB pixel values for // us from
// the image.
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
}
return pixels;
}
ImageProcessor.java 文件源码
项目:Library-of-Kaeon
阅读 35
收藏 0
点赞 0
评论 0
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();
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 23
收藏 0
点赞 0
评论 0
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));
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 24
收藏 0
点赞 0
评论 0
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));
}
BufferedImageUtils.java 文件源码
项目:PhET
阅读 21
收藏 0
点赞 0
评论 0
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();
}
OutputPaneController.java 文件源码
项目:BrickifyFX
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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;
}
BMPFile.java 文件源码
项目:WarpPI
阅读 23
收藏 0
点赞 0
评论 0
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);
}
ImageScaler.java 文件源码
项目:communote-server
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
Camera.java 文件源码
项目:axisviewer
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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
}
Sprite.java 文件源码
项目:osrs-private-server
阅读 22
收藏 0
点赞 0
评论 0
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");
}
}
Sprite.java 文件源码
项目:osrs-private-server
阅读 34
收藏 0
点赞 0
评论 0
public Sprite(String img, int width, int height) {
try {
Image image = Toolkit.getDefaultToolkit().createImage(FileOperations.ReadFile(img));
myWidth = width;
myHeight = height;
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();
image = null;
} catch (Exception _ex) {
System.out.println(_ex);
}
}
Sprite.java 文件源码
项目:osrs-private-server
阅读 30
收藏 0
点赞 0
评论 0
public Sprite(String img) {
try {
Image image = Toolkit.getDefaultToolkit().getImage(location + img + ".png");
ImageIcon sprite = new ImageIcon(image);
myWidth = sprite.getIconWidth();
myHeight = sprite.getIconHeight();
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();
image = null;
setTransparency(255, 0, 255);
} catch (Exception _ex) {
System.out.println(_ex);
}
}
Sprite.java 文件源码
项目:osrs-private-server
阅读 26
收藏 0
点赞 0
评论 0
public Sprite(byte spriteData[]) {
try {
Image image = Toolkit.getDefaultToolkit().createImage(spriteData);
ImageIcon sprite = new ImageIcon(image);
myWidth = sprite.getIconWidth();
myHeight = sprite.getIconHeight();
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();
image = null;
setTransparency(255, 0, 255);
} catch (Exception _ex) {
System.out.println(_ex);
}
}
UIUtil.java 文件源码
项目:intellij-ce-playground
阅读 33
收藏 0
点赞 0
评论 0
@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;
}
Util.java 文件源码
项目:project-bianca
阅读 27
收藏 0
点赞 0
评论 0
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();
}
ImageOperations.java 文件源码
项目:cmoct-sourcecode
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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();
}
ImageUtils.java 文件源码
项目:plg
阅读 32
收藏 0
点赞 0
评论 0
/**
* Given an image, this method extracts a color that is calculated as the
* average of the colors of the image
*
* @param image the given image
* @return the "average" color
*/
public static Color getAverageColor(BufferedImage image) {
if (image == null) {
return null;
}
Image i = image.getScaledInstance(1, 1, BufferedImage.SCALE_SMOOTH);
int[] pixels = new int[1];
PixelGrabber pg = new PixelGrabber(i, 0, 0, 1, 1, pixels, 0, 1);
try {
pg.grabPixels();
} catch (InterruptedException e) { }
int c = pixels[0];
int red = (c & 0x00ff0000) >> 16;
int green = (c & 0x0000ff00) >> 8;
int blue = c & 0x000000ff;
return new Color(red, green, blue);
}
ImageUtils.java 文件源码
项目:plg
阅读 39
收藏 0
点赞 0
评论 0
/**
* Given an image, this method extracts a color that is calculated as the
* average of the colors of the image
*
* @param image the given image
* @return the "average" color
*/
public static Color getAverageColor(BufferedImage image) {
if (image == null) {
return null;
}
Image i = image.getScaledInstance(1, 1, BufferedImage.SCALE_SMOOTH);
int[] pixels = new int[1];
PixelGrabber pg = new PixelGrabber(i, 0, 0, 1, 1, pixels, 0, 1);
try {
pg.grabPixels();
} catch (InterruptedException e) { }
int c = pixels[0];
int red = (c & 0x00ff0000) >> 16;
int green = (c & 0x0000ff00) >> 8;
int blue = c & 0x000000ff;
return new Color(red, green, blue);
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 19
收藏 0
点赞 0
评论 0
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));
}
xtGraphics.java 文件源码
项目:OpenNFMM
阅读 21
收藏 0
点赞 0
评论 0
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));
}
DvidMultiscale2dVolatileArrayLoader.java 文件源码
项目:bigcat
阅读 23
收藏 0
点赞 0
评论 0
static private void readImage(
final String urlString,
final int w,
final int h,
final int[] data ) throws IOException, InterruptedException
{
final URL url = new URL( urlString );
final BufferedImage jpg = ImageIO.read( url );
/* This gymnastic is necessary to get reproducible gray
* values, just opening a JPG or PNG, even when saved by
* ImageIO, and grabbing its pixels results in gray values
* with a non-matching gamma transfer function, I cannot tell
* why... */
final BufferedImage image =
new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
image.createGraphics().drawImage( jpg, 0, 0, null );
final PixelGrabber pg = new PixelGrabber( image, 0, 0, w, h, data, 0, w );
pg.grabPixels();
}
IconGenerator.java 文件源码
项目:onecmdb
阅读 21
收藏 0
点赞 0
评论 0
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();
}
ImageDrawingArea.java 文件源码
项目:jhack
阅读 20
收藏 0
点赞 0
评论 0
/**
* Returns the Color of point x, y on the image. Uses
* <code>PixelGrabber</code> to get the exact color.
*
* @param x Coordinate on the image.
* @param y Coordinate on the image.
* @return The Color of the specified point.
*/
public Color getPointColor(int x, int y)
{
// return new Color(((BufferedImage) img).getRGB(x, y));
int w = 1, h = 1;
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try
{
pg.grabPixels();
}
catch (InterruptedException e)
{
System.err.println("interrupted waiting for pixels!");
return null;
}
int alpha, blue, red, green;
alpha = (pixels[0] >> 24) & 0xff;
red = (pixels[0] >> 16) & 0xff;
green = (pixels[0] >> 8) & 0xff;
blue = (pixels[0]) & 0xff;
return new Color(red, green, blue, alpha);
}
Image.java 文件源码
项目:Lucee4
阅读 24
收藏 0
点赞 0
评论 0
/**
* This method returns true if the specified image has transparent pixels
* @param image
* @return
*/
public static boolean hasAlpha(java.awt.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();
}
ImageUtils.java 文件源码
项目:Lucee4
阅读 28
收藏 0
点赞 0
评论 0
/**
* Cretae a BufferedImage from an ImageProducer.
* @param producer the ImageProducer
* @return a new TYPE_INT_ARGB BufferedImage
*/
public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0)
throw new RuntimeException("Image fetch aborted");
if ((pg.status() & ImageObserver.ERROR) != 0)
throw new RuntimeException("Image fetch error");
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
return p;
}
Effect.java 文件源码
项目:seaglass
阅读 33
收藏 0
点赞 0
评论 0
/**
* This method returns true if the specified image has transparent pixels
*
* @param image an image.
*
* @return {@code true} if the image has transparent pixels, {@code false}
* otherwise.
*/
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();
}
// 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();
}
TransparentFilter.java 文件源码
项目:vassal
阅读 17
收藏 0
点赞 0
评论 0
/**
* 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];
}