use of java.awt.Graphics2D in project opennms by OpenNMS.
the class TimelineRestService method image.
@GET
@Produces("image/png")
@Transactional
@Path("image/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response image(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @PathParam("ipAddress") final String ipAddress, @PathParam("serviceName") final String serviceName, @PathParam("start") final long start, @PathParam("end") final long end, @PathParam("width") final int width) throws IOException {
long delta = end - start;
OnmsOutageCollection onmsOutageCollection = queryOutages(uriInfo, nodeId, ipAddress, serviceName, start, end);
BufferedImage bufferedImage = new BufferedImage(width, 20, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();
graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
graphics2D.setColor(Color.BLACK);
int numLabels = TimescaleDescriptor.computeNumberOfLabels(graphics2D, delta, width);
for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
if (desc.match(delta, numLabels)) {
desc.drawGreen(graphics2D, width);
for (OnmsOutage onmsOutage : onmsOutageCollection) {
desc.drawEvent(graphics2D, delta, start, width, onmsOutage);
}
desc.drawLine(graphics2D, delta, start, width);
break;
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", baos);
byte[] imageData = baos.toByteArray();
return Response.ok(imageData).build();
}
use of java.awt.Graphics2D in project jdk8u_jdk by JetBrains.
the class BMPPluginTest method createTestImage.
private static BufferedImage createTestImage(int type) throws IOException {
int w = 200;
int h = 200;
BufferedImage b = new BufferedImage(w, h, type);
Graphics2D g = b.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
g.setColor(Color.black);
g.fillOval(10, 10, w - 20, h - 20);
return b;
}
use of java.awt.Graphics2D in project jdk8u_jdk by JetBrains.
the class BMPSubsamplingTest method getTestImage.
private BufferedImage getTestImage(int type) {
BufferedImage dst = null;
ColorModel colorModel = null;
WritableRaster raster = null;
switch(type) {
case TYPE_INT_GRB:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
break;
case TYPE_INT_GBR:
colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
break;
case TYPE_INT_RBG:
colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
break;
case TYPE_INT_BRG:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
break;
case TYPE_3BYTE_RGB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 0, 1, 2 });
break;
case TYPE_3BYTE_GRB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 1, 0, 2 });
break;
case TYPE_USHORT_555_GRB:
colorModel = new DirectColorModel(16, 0x03E0, 0x7C00, 0x001F);
break;
case TYPE_USHORT_555_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x03E0, 0x7C00);
break;
case TYPE_USHORT_565_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x07E0, 0xf800);
break;
case TYPE_4BPP_INDEXED:
dst = createIndexImage(4);
break;
default:
dst = new BufferedImage(w, h, type);
}
if (dst == null) {
raster = colorModel.createCompatibleWritableRaster(w, h);
dst = new BufferedImage(colorModel, raster, false, null);
}
Graphics2D g = dst.createGraphics();
for (int i = 0; i < colors.length; i++) {
g.setColor(colors[i]);
g.fillRect(i * dx, 0, dx, h);
}
g.dispose();
return dst;
}
use of java.awt.Graphics2D in project jdk8u_jdk by JetBrains.
the class HelvLtOblTest method drawText.
BufferedImage drawText(boolean doGV) {
int w = 400;
int h = 50;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
g.setColor(Color.black);
Font f = helvFont.deriveFont(Font.PLAIN, 40);
g.setFont(f);
int x = 5;
int y = h - 10;
if (doGV) {
FontRenderContext frc = new FontRenderContext(null, true, true);
GlyphVector gv = f.createGlyphVector(frc, codes);
g.drawGlyphVector(gv, 5, y);
} else {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.drawString(str, x, y);
}
return bi;
}
use of java.awt.Graphics2D in project jdk8u_jdk by JetBrains.
the class BMPWriteParamTest method createTestImage.
private static BufferedImage createTestImage() throws IOException {
int w = 50;
int h = 50;
BufferedImage b = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = b.createGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, w, h);
g.setColor(Color.white);
for (int i = 10; i <= 10 + 30; i += 3) {
g.drawLine(i, 10, i, 40);
g.drawLine(10, i, 40, i);
}
return b;
}
Aggregations