use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.
the class GradientPalletProgressBarUI method makeGradientPallet.
private static int[] makeGradientPallet() {
BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
Point2D start = new Point2D.Float();
Point2D end = new Point2D.Float(99f, 0f);
float[] dist = { 0f, .5f, 1f };
Color[] colors = { Color.RED, Color.YELLOW, Color.GREEN };
g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
g2.fillRect(0, 0, 100, 1);
g2.dispose();
int width = image.getWidth(null);
int[] pallet = new int[width];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
try {
pg.grabPixels();
} catch (InterruptedException ex) {
ex.printStackTrace();
Toolkit.getDefaultToolkit().beep();
Thread.currentThread().interrupt();
}
return pallet;
}
use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.
the class MissingIcon method makeRoundedMemoryImageSource.
private static Optional<MemoryImageSource> makeRoundedMemoryImageSource(Image img, int w, int h) {
int[] pix = new int[h * w];
PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException ex) {
System.err.println("interrupted waiting for pixels!");
ex.printStackTrace();
Thread.currentThread().interrupt();
return Optional.empty();
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or error");
return Optional.empty();
}
Area area = makeNorthWestCorner();
Rectangle r = area.getBounds();
// NW
Shape s = area;
for (int y = 0; y < r.height; y++) {
for (int x = 0; x < r.width; x++) {
if (s.contains(x, y)) {
pix[x + y * w] = 0x0;
}
}
}
AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
at.translate(-w, 0);
// NE
s = at.createTransformedShape(area);
for (int y = 0; y < r.height; y++) {
for (int x = w - r.width; x < w; x++) {
if (s.contains(x, y)) {
pix[x + y * w] = 0x0;
}
}
}
return Optional.of(new MemoryImageSource(w, h, pix, 0, w));
}
use of java.awt.image.PixelGrabber in project java-swing-tips by aterai.
the class ProgressListener method makeGradientPallet.
private static int[] makeGradientPallet(int range) {
BufferedImage image = new BufferedImage(range, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
Point2D start = new Point2D.Float();
Point2D end = new Point2D.Float(range - 1f, 0f);
float[] dist = { 0f, .8f, .9f, 1f };
Color[] colors = { Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED };
g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
g2.fillRect(0, 0, range, 1);
g2.dispose();
int width = image.getWidth(null);
int[] pallet = new int[width];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
try {
pg.grabPixels();
} catch (InterruptedException ex) {
ex.printStackTrace();
Toolkit.getDefaultToolkit().beep();
Thread.currentThread().interrupt();
}
return pallet;
}
use of java.awt.image.PixelGrabber in project openchemlib by Actelion.
the class WMFGraphics method setGDIFillBrush.
public int setGDIFillBrush() {
int i = brushhandle;
if (brushfillstyle == 3) {
if (brushpattern != null) {
int j = brushpattern.getWidth(null);
int k = brushpattern.getHeight(null);
int[] ai = new int[j * k];
PixelGrabber pixelgrabber = new PixelGrabber(brushpattern, 0, 0, j, k, ai, 0, j);
try {
pixelgrabber.grabPixels();
if ((pixelgrabber.status() & 0x80) != 0) {
brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
} else {
brushhandle = wmf.createPatternBrush(ai, j, k);
}
} catch (InterruptedException _ex) {
brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
}
} else {
brushhandle = wmf.createBrushIndirect(0, foreground, brushhatch);
}
} else {
brushhandle = wmf.createBrushIndirect(brushfillstyle, foreground, brushhatch);
}
wmf.selectObject(brushhandle);
wmf.deleteObject(i);
state.setBrush(brushhandle);
return brushhandle;
}
use of java.awt.image.PixelGrabber in project runelite by runelite.
the class ImageUtil method getImageSpritePixels.
/**
* Converts the buffered image into a sprite image and returns it
* @param image The image to be converted
* @param client Current client instance
* @return The buffered image as a sprite image
*/
public static SpritePixels getImageSpritePixels(BufferedImage image, Client client) {
int[] pixels = new int[image.getWidth() * image.getHeight()];
try {
PixelGrabber g = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
g.setColorModel(new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000));
g.grabPixels();
// check for == 0, not actual transparency
for (int i = 0; i < pixels.length; i++) {
if ((pixels[i] & 0xFF000000) == 0) {
pixels[i] = 0;
}
}
} catch (InterruptedException ex) {
log.debug("PixelGrabber was interrupted: ", ex);
}
return client.createSpritePixels(pixels, image.getWidth(), image.getHeight());
}
Aggregations