use of java.awt.image.PixelGrabber in project narchy by automenta.
the class ClipBMP method convertImage.
/*
* convertImage converts the memory image to the bitmap format (BRG). It
* also computes some information for the bitmap info header.
*
*/
private boolean convertImage(Image parImage, int parWidth, int parHeight) {
int pad;
bitmap = new int[parWidth * parHeight];
PixelGrabber pg = new PixelGrabber(parImage, 0, 0, parWidth, parHeight, bitmap, 0, parWidth);
try {
pg.grabPixels();
} catch (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);
}
use of java.awt.image.PixelGrabber in project narchy by automenta.
the class Texture method drawImage.
/**
* Draw an image
*
* @param x
* X
* @param y
* Y
* @param image
* Image to draw
*/
public void drawImage(final int x, final int y, final Image image) {
PixelGrabber pixelGrabber;
ColorModel colorModel;
int width;
int height;
int[] pixels;
boolean mayTransparent;
image.flush();
width = image.getWidth(null);
height = image.getHeight(null);
pixels = new int[width * height];
pixelGrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
try {
if (pixelGrabber.grabPixels() == true) {
mayTransparent = true;
colorModel = pixelGrabber.getColorModel();
if (colorModel != null) {
mayTransparent = colorModel.hasAlpha();
}
this.drawImage(x, y, pixels, width, height, mayTransparent);
}
} catch (final InterruptedException e) {
Debug.printException(e, "Issue while extracting pixels");
}
pixels = null;
colorModel = null;
pixelGrabber = null;
}
use of java.awt.image.PixelGrabber in project narchy by automenta.
the class ClipBMP method convertImage.
/*
* convertImage converts the memory image to the bitmap format (BRG). It
* also computes some information for the bitmap info header.
*
*/
private boolean convertImage(Image parImage, int parWidth, int parHeight) {
int pad;
bitmap = new int[parWidth * parHeight];
PixelGrabber pg = new PixelGrabber(parImage, 0, 0, parWidth, parHeight, bitmap, 0, parWidth);
try {
pg.grabPixels();
} catch (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);
}
use of java.awt.image.PixelGrabber in project cytoscape-impl by cytoscape.
the class ImageUtil method toBufferedImage.
public static BufferedImage toBufferedImage(final Image image) throws InterruptedException {
if (image instanceof BufferedImage)
return (BufferedImage) image;
MediaTracker tracker = new MediaTracker(new Component() {
});
tracker.addImage(image, 0);
tracker.waitForAll();
PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, false);
pixelGrabber.grabPixels();
ColorModel cm = pixelGrabber.getColorModel();
final int w = pixelGrabber.getWidth();
final int h = pixelGrabber.getHeight();
WritableRaster raster = cm.createCompatibleWritableRaster(w, h);
final BufferedImage renderedImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), new Hashtable());
renderedImage.getRaster().setDataElements(0, 0, w, h, pixelGrabber.getPixels());
return renderedImage;
}
use of java.awt.image.PixelGrabber in project imagej1 by imagej.
the class ByteProcessorTest method testByteProcessorImage.
@Test
public void testByteProcessorImage() {
java.awt.image.ColorModel cm = new ByteProcessor(width, height, getImageByteData(), null).getColorModel();
byte[] pixels8 = getImageByteData();
java.awt.image.MemoryImageSource source = new MemoryImageSource(width, height, cm, pixels8, 0, width);
source.setAnimated(true);
source.setFullBufferUpdates(true);
java.awt.Image refImage = Toolkit.getDefaultToolkit().createImage(source);
// find the test data
byte[] testByteProcessor = new ByteProcessor(refImage).create8BitImage();
// find the reference data
PixelGrabber pg = new PixelGrabber(refImage, 0, 0, width, height, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println(e);
}
byte[] refImageArray = (byte[]) pg.getPixels();
// check the values
for (int index = 0; index < refImageArray.length; index++) {
// System.out.println( (refByteArray[index]&0xff) + " " + index + " " + testByteProcessor.get(index) );
assertEquals(refImageArray[index], testByteProcessor[index], 0.0);
}
}
Aggregations