use of java.awt.image.BufferedImage in project openblocks by mikaelhg.
the class CRadioactiveButton method paint.
@Override
public void paint(Graphics g) {
// Set up graphics and buffer
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
BufferedImage buffer = GraphicsManager.gc.createCompatibleImage(this.getWidth(), this.getHeight(), Transparency.TRANSLUCENT);
Graphics2D gb = buffer.createGraphics();
gb.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set up first layer
int buttonHeight = this.getHeight() - INSET * 2;
int buttonWidth = this.getWidth() - INSET * 2;
int arc = buttonHeight;
if (this.pressed || this.selected) {
g2.setPaint(new GradientPaint(0, -buttonHeight, Color.darkGray, 0, buttonHeight, buttonColor, false));
g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
g2.setColor(Color.darkGray);
g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
} else {
//paint highlightlayer
if (this.focus) {
gb.setColor(Color.yellow);
gb.setStroke(new BasicStroke(3));
gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
gb.setStroke(new BasicStroke(1));
}
// Paint the first layer
gb.setColor(buttonColor.darker());
gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
gb.setColor(Color.darkGray);
gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// set up paint data fields for second layer
int highlightHeight = buttonHeight * 2 / 3;
int highlightWidth = buttonWidth;
int highlightArc = highlightHeight;
// Paint the second layer
gb.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
gb.setColor(buttonColor);
gb.setClip(new RoundRectangle2D.Float(INSET, INSET, highlightWidth, highlightHeight, highlightArc, highlightArc));
gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// Blur
ConvolveOp blurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
BufferedImage blurredImage = blurOp.filter(buffer, null);
// Draw button
g2.drawImage(blurredImage, 1, 1, null);
}
// Draw the text (if any)
String text = this.getText();
if (text != null && buttonHeight > 4) {
//Font font = g2.getFont().deriveFont((float)(((float)this.getHeight()) * .6));
Font font = g2.getFont().deriveFont((float) (this.getHeight() - INSET * 2 - 2) * .7f);
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics();
Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
g.setColor(Color.black);
for (int i = 0; i < shadowPositionArray.length; i++) {
int dx = shadowPositionArray[i][0];
int dy = shadowPositionArray[i][1];
g2.setColor(new Color(0, 0, 0, shadowColorArray[i]));
g2.drawString(text, x + (int) ((dx) * offsetSize), y + (int) ((dy) * offsetSize));
}
g2.setColor(Color.white);
g2.drawString(text, x, y);
}
}
use of java.awt.image.BufferedImage in project d54 by mitrisdev.
the class GNU30Plugin method loadIndex.
protected void loadIndex() throws IOException {
InputStream stream = GNU30Plugin.class.getResourceAsStream("/resources/gnu30/images.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = br.readLine()) != null) {
String path = "/images/gnu30/" + line.trim();
ArrayList<BufferedImage> bi = this.loadGifObject(GNU30Plugin.class.getResourceAsStream(path));
this.images.add(bi);
}
this.loadGif(0);
}
use of java.awt.image.BufferedImage in project d54 by mitrisdev.
the class Display2D method endFrame.
/**
* This method indicates that the frame is finished being rendered. The {@link DisplayListener}s are notified about the new frame.
*/
public void endFrame() {
bufferedData = imageData;
imageData = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (DisplayListener l : displayListeners) {
l.displayUpdated(this);
}
}
use of java.awt.image.BufferedImage in project joons-renderer by joonhyublee.
the class JRImagePanel method imageBegin.
@Override
public synchronized void imageBegin(int w, int h, int bucketSize) {
if (image != null && w == image.getWidth() && h == image.getHeight()) {
// dull image if it has same resolution (75%)
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int rgba = image.getRGB(x, y);
image.setRGB(x, y, ((rgba & 0xFEFEFEFE) >>> 1) + ((rgba & 0xFCFCFCFC) >>> 2));
}
}
} else {
// allocate new framebuffer
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// center
this.w = w;
this.h = h;
xo = yo = 0;
}
repaintCounter = System.nanoTime();
repaint();
}
use of java.awt.image.BufferedImage in project jersey by jersey.
the class SparklinesResource method smooth.
@Path("smooth")
@GET
public Response smooth(@DefaultValue("2") @QueryParam("step") final int step, @DefaultValue("true") @QueryParam("min-m") final boolean hasMin, @DefaultValue("true") @QueryParam("max-m") final boolean hasMax, @DefaultValue("true") @QueryParam("last-m") final boolean hasLast, @DefaultValue("blue") @QueryParam("min-color") final ColorParam minColor, @DefaultValue("green") @QueryParam("max-color") final ColorParam maxColor, @DefaultValue("red") @QueryParam("last-color") final ColorParam lastColor) {
final BufferedImage image = new BufferedImage(data.size() * step - 4, imageHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.gray);
final int[] xs = new int[data.size()];
final int[] ys = new int[data.size()];
final int gap = 4;
final float d = (limits.width() + 1) / (float) (imageHeight - gap);
for (int i = 0, x = 0; i < data.size(); i++, x += step) {
final int v = data.get(i);
xs[i] = x;
ys[i] = imageHeight - 3 - (int) ((v - limits.lower()) / d);
}
g.drawPolyline(xs, ys, data.size());
if (hasMin) {
final int i = data.indexOf(Collections.min(data));
g.setColor(minColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);
}
if (hasMax) {
final int i = data.indexOf(Collections.max(data));
g.setColor(maxColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);
}
if (hasMax) {
g.setColor(lastColor);
g.fillRect(xs[xs.length - 1] - step / 2, ys[ys.length - 1] - step / 2, step, step);
}
return Response.ok(image).tag(tag).build();
}
Aggregations