List of usage examples for java.awt AlphaComposite SrcOver
AlphaComposite SrcOver
To view the source code for java.awt AlphaComposite SrcOver.
Click Source Link
From source file:com.zacwolf.commons.email.Email.java
public static BufferedImage makeRoundedFooter(int width, int cornerRadius, Color bgcolor, Color border) throws Exception { int height = (cornerRadius * 2) + 10; BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(bgcolor);/* w w w. j a va2 s . c om*/ g2.fillRoundRect(0, 0, width, height - 1, cornerRadius, cornerRadius); g2.setComposite(AlphaComposite.SrcOver); if (border != null) { g2.setColor(border); g2.drawRoundRect(0, 0, width - 1, height - 2, cornerRadius, cornerRadius); } g2.dispose(); Rectangle clip = createClip(output, new Dimension(width, cornerRadius), 0, height - cornerRadius - 1); return output.getSubimage(clip.x, clip.y, clip.width, clip.height); }
From source file:MyJava3D.java
public Graphics2D createGraphics2D(int width, int height, BufferedImage bi, Graphics g) { Graphics2D g2 = null;// ww w .j a v a2 s .c o m if (bi != null) { g2 = bi.createGraphics(); } else { g2 = (Graphics2D) g; } g2.setBackground(getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, AntiAlias); g2.setRenderingHint(RenderingHints.KEY_RENDERING, Rendering); if (clearSurface || clearOnce) { g2.clearRect(0, 0, width, height); clearOnce = false; } if (texture != null) { // set composite to opaque for texture fills g2.setComposite(AlphaComposite.SrcOver); g2.setPaint(texture); g2.fillRect(0, 0, width, height); } if (composite != null) { g2.setComposite(composite); } return g2; }
From source file:org.apache.fop.afp.AFPGraphics2D.java
/** * Draws an AWT image into a BufferedImage using an AWT Graphics2D implementation * * @param img the AWT image//from w w w . jav a 2 s . c om * @param bufferedImage the AWT buffered image * @param width the image width * @param height the image height * @param observer the image observer * @return true if the image was drawn */ private boolean drawBufferedImage(Image img, BufferedImage bufferedImage, int width, int height, ImageObserver observer) { java.awt.Graphics2D g2d = bufferedImage.createGraphics(); try { g2d.setComposite(AlphaComposite.SrcOver); Color color = new Color(1, 1, 1, 0); g2d.setBackground(color); g2d.setPaint(color); g2d.fillRect(0, 0, width, height); int imageWidth = bufferedImage.getWidth(); int imageHeight = bufferedImage.getHeight(); Rectangle clipRect = new Rectangle(0, 0, imageWidth, imageHeight); g2d.clip(clipRect); g2d.setComposite(gc.getComposite()); return g2d.drawImage(img, 0, 0, imageWidth, imageHeight, observer); } finally { g2d.dispose(); //drawn so dispose immediately to free system resource } }
From source file:org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D.java
private BufferedImage getImage(int width, int height, Image img, ImageObserver observer) { Dimension size = new Dimension(width, height); BufferedImage buf = buildBufferedImage(size); Graphics2D g = buf.createGraphics(); g.setComposite(AlphaComposite.SrcOver); g.setBackground(new Color(1, 1, 1, 0)); g.fillRect(0, 0, width, height);//from www .j ava 2 s. co m g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); if (!g.drawImage(img, 0, 0, observer)) { return null; } g.dispose(); return buf; }
From source file:test.uk.co.modularaudio.util.audio.controlinterpolation.InterpolatorVisualiser.java
public void interpolateEvents(final TestEvent[] events) { int lastEventIndex = events[events.length - 1].getOffsetInSamples(); final float[] vals = new float[lastEventIndex]; final int numEvents = events.length; int curOutputOffset = 0; for (int i = 1; i < numEvents; ++i) { final int eventOffset = events[i].getOffsetInSamples(); // Generate using the interpolator up to this event final int numForThisEvent = eventOffset - curOutputOffset; valueInterpolator.generateControlValues(vals, curOutputOffset, numForThisEvent); final float newValue = events[i].getEventValue(); // log.debug("Using newValue " + newValue ); valueInterpolator.notifyOfNewValue(newValue); curOutputOffset += numForThisEvent; }// w w w .j av a2 s . co m if (curOutputOffset < lastEventIndex) { valueInterpolator.generateControlValues(vals, curOutputOffset, SwingControlInterpolatorAnalyser.VIS_WIDTH - curOutputOffset); } g2d.setComposite(AlphaComposite.Clear); g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, SwingControlInterpolatorAnalyser.VIS_WIDTH + 1, SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1); g2d.setComposite(AlphaComposite.SrcOver); // If we are the src signal, // draw some lines where we have events if (controlSrcVisualiser == null) { g2d.setColor(new Color(0.6f, 0.6f, 1.0f)); for (int i = 1; i < numEvents; ++i) { final int eventOffset = events[i].getOffsetInSamples(); final int eventPosInPixels = eventOffset / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL; g2d.drawLine(eventPosInPixels, 0, eventPosInPixels, SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1); } } if (controlSrcVisualiser == null) { g2d.setColor(Color.RED); } else { g2d.setColor(Color.BLACK); } int previousY = (int) (vals[0] * SwingControlInterpolatorAnalyser.VIS_HEIGHT); for (int i = 1; i < lastEventIndex; ++i) { final float val = vals[i]; final float asYValue = val * SwingControlInterpolatorAnalyser.VIS_HEIGHT; final int asYInt = (int) asYValue; final int x1 = (i - 1) / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL; final int y1 = previousY; final int x2 = i / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL; final int y2 = asYInt; // log.debug("Drawing line from " + x1 + ", " + y1 + " to " + x2 + ", " + y2 ); g2d.drawLine(x1, SwingControlInterpolatorAnalyser.VIS_HEIGHT - y1, x2, SwingControlInterpolatorAnalyser.VIS_HEIGHT - y2); previousY = y2; } repaint(); }
From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java
private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) { // log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint); final int fromX = sourcePoint.x; final int fromY = sourcePoint.y; final int toX = sinkPoint.x; final int toY = sinkPoint.y; float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f; f1 = fromX;//from w w w .ja v a2 s .c o m f2 = fromY; f3 = fromX; f4 = fromY + WIRE_DIP_PIXELS; f5 = toX; f6 = toY + WIRE_DIP_PIXELS; f7 = toX; f8 = toY; final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); final Rectangle cubicCurveBounds = cubicCurve.getBounds(); final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS; // int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS; int imageHeightToUse = cubicCurveBounds.height; // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip" if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) { imageHeightToUse += (WIRE_DIP_PIXELS / 2); } // bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB ); try { tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource, allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB, imageWidthToUse, imageHeightToUse); bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage(); final Graphics2D g2d = bufferedImage.createGraphics(); g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse); g2d.setComposite(AlphaComposite.SrcOver); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); // Draw the highlight and shadow if (DRAW_HIGHTLIGHT_AND_SHADOW) { final Graphics2D sG2d = (Graphics2D) g2d.create(); sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET); sG2d.setColor(Color.BLUE.darker()); sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); sG2d.draw(offSetCubicCurve); final Graphics2D hG2d = (Graphics2D) g2d.create(); hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET); hG2d.setColor(Color.WHITE); hG2d.setStroke( new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); hG2d.draw(offSetCubicCurve); } g2d.setColor(Color.BLACK); g2d.setStroke(wireStroke); g2d.draw(offSetCubicCurve); g2d.setColor(Color.BLUE); g2d.setStroke(wireBodyStroke); g2d.draw(offSetCubicCurve); // For debugging, draw a green line around the outside of this image. if (DRAW_WIRE_BOUNDING_BOX) { g2d.setStroke(basicStrokeOfOne); g2d.setColor(Color.GREEN); g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1); } rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER; rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER; rectangle.width = imageWidthToUse; rectangle.height = imageHeightToUse; } catch (final Exception e) { final String msg = "Exception caught allocating buffered image: " + e.toString(); log.error(msg, e); } }