use of java.awt.image.PixelGrabber in project BombusMod by BombusMod.
the class J2SEMutableImage method getData.
public int[] getData() {
if (grabber == null) {
pixels = new int[getWidth() * getHeight()];
grabber = new PixelGrabber(graphicsSurface.getImage(), 0, 0, getWidth(), getHeight(), pixels, 0, getWidth());
}
try {
grabber.grabPixels();
} catch (InterruptedException e) {
logger.error("AWT exception", e);
}
return pixels;
}
use of java.awt.image.PixelGrabber in project vcell by virtualcell.
the class NativeImage method createPixels.
/**
* This method was created in VisualAge.
* @return byte[]
*/
private void createPixels() throws Exception {
if (bPixelsExist()) {
return;
}
PixelGrabber pg = new PixelGrabber(getJavaImage(), 0, 0, getSize().getX(), getSize().getX(), false);
if (!pg.grabPixels()) {
throw new Exception("Error getting pixels, status = " + pg.getStatus());
}
Object pixels = pg.getPixels();
ColorModel colorModel = null;
while (colorModel == null) {
colorModel = pg.getColorModel();
}
if ((pixels instanceof int[]) && (colorModel instanceof DirectColorModel)) {
newRGBAPixels = (int[]) pixels;
} else if ((pixels instanceof byte[]) && (colorModel instanceof IndexColorModel)) {
newIndexPixels = (byte[]) pixels;
IndexColorModel indexColorModel = (IndexColorModel) colorModel;
int colorMapSize = indexColorModel.getMapSize();
byte[] temp_colorMap = new byte[colorMapSize * IndexColorMap.RGB_PACK_SIZE];
byte[] reds = new byte[colorMapSize];
indexColorModel.getReds(reds);
byte[] greens = new byte[colorMapSize];
indexColorModel.getGreens(greens);
byte[] blues = new byte[colorMapSize];
indexColorModel.getBlues(blues);
for (int c = 0; c < colorMapSize; c += 1) {
// make packed R,G,B array for ColorIndexModel
int packCount = c * IndexColorMap.RGB_PACK_SIZE;
temp_colorMap[packCount] = reds[c];
temp_colorMap[packCount + 1] = greens[c];
temp_colorMap[packCount + 2] = blues[c];
}
colorMap = new IndexColorMap(temp_colorMap);
} else {
throw new Exception("Unknown combination of data type=" + pixels.getClass().toString() + " and ColorModel=" + colorModel.getClass().toString());
}
}
use of java.awt.image.PixelGrabber in project hale by halestudio.
the class ImageMarker method hasAlpha.
/**
* Determines if an image has transparent pixels
*
* @param image the {@link Image}
* @return if the given 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) {
// ignore
}
// Get the image's color model
ColorModel cm = pg.getColorModel();
return cm.hasAlpha();
}
use of java.awt.image.PixelGrabber in project gephi by gephi.
the class UIUtils method getGTKProfilerResultsBackground.
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) {
// System background not customized
return Color.WHITE;
}
} catch (InterruptedException e) {
return getNonGTKProfilerResultsBackground();
}
return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground();
}
use of java.awt.image.PixelGrabber in project gephi by gephi.
the class JImagePanel method setPreferredBackground.
protected void setPreferredBackground() {
int[] pixels = new int[1];
PixelGrabber pg = null;
switch(imageAlign) {
case (SwingConstants.TOP):
pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
break;
case (SwingConstants.BOTTOM):
pg = new PixelGrabber(image, 0, 0, 1, 1, pixels, 0, 1);
break;
default:
pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1);
}
try {
if ((pg != null) && pg.grabPixels()) {
setBackground(new Color(pixels[0]));
}
} catch (InterruptedException e) {
}
}
Aggregations