boolean isScaledUp = pdImage.getWidth() < Math.round(at.getScaleX()) || pdImage.getHeight() < Math.round(at.getScaleY()); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1); Rectangle2D bounds = at.createTransformedShape(unitRect).getBounds2D(); BufferedImage renderedPaint = new BufferedImage((int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight()), BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) renderedPaint.getGraphics(); g.translate(-bounds.getMinX(), -bounds.getMinY()); g.setPaint(paint); g.fill(bounds); g.dispose(); BufferedImage renderedMask = new BufferedImage((int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight()), BufferedImage.TYPE_INT_RGB);
/** * Paints the background of a token. * * @param x The x-coordinate of the token. * @param y The y-coordinate of the token. * @param width The width of the token (actually, the width of the part of * the token to paint). * @param height The height of the token. * @param g The graphics context with which to paint. * @param fontAscent The ascent of the token's font. * @param host The text area. * @param color The color with which to paint. */ protected void paintBackground(float x, float y, float width, float height, Graphics2D g, int fontAscent, RSyntaxTextArea host, Color color) { g.setColor(color); bgRect.setRect(x,y-fontAscent, width,height); //g.fill(bgRect); g.fillRect((int)x, (int)(y-fontAscent), (int)width, (int)height); }
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { Graphics2D g2 = (Graphics2D)g.create(); g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); int r = DEF_DIAMETER; g2.translate( x, y ); g2.setColor( _color ); g2.fillRect( r/2, 0, width - r - 1, _insets.top ); g2.fillRect( 0, r/2, _insets.left, height - r - 1 ); g2.fillRect( r/2 , height - _insets.bottom - 1, width - r - 1, _insets.bottom ); g2.fillRect( width - _insets.right - 1, r/2, _insets.right, height - r - 1 ); RoundRectangle2D round = new RoundRectangle2D.Float( 0, 0, width - 1, height - 1, r, r ); Container parent = c.getParent(); if( parent != null ) { g2.setColor( parent.getBackground() ); Area corner = new Area( new Rectangle2D.Float( 0, 0, width, height ) ); corner.subtract( new Area( round ) ); g2.fill( corner ); } BasicStroke stroke = new BasicStroke( 1.0f ); g2.setStroke( stroke ); g2.setColor( _color ); g2.draw( new Arc2D.Double( 0, 0, r, r, 90, 90, Arc2D.OPEN ) ); g2.draw( new Arc2D.Double( width - r - 2, 0, r, r, 90, -90, Arc2D.OPEN ) ); g2.draw( new Arc2D.Double( width - r - 2, height - r - 2, r, r, 0, -90, Arc2D.OPEN ) ); g2.draw( new Arc2D.Double( 0, height - r - 2, r, r, 180, 90, Arc2D.OPEN ) ); g2.dispose(); }
Color fill = new Color(208, 208, 48); Graphics2D graphics = (Graphics2D) result.getGraphics().create(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); .getBorderStrokeWidth(componentFontSize) / 1.2f; float extraInsets = borderStrokeWidth / 2.0f; graphics.setStroke(new BasicStroke(borderStrokeWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND)); graphics.setColor(fill); graphics.fill(new Rectangle2D.Float(lockPadLeft, lockPadTop, lockPadRight - lockPadLeft, lockPadBottom - lockPadTop)); graphics.setColor(fore); graphics.draw(new Rectangle2D.Float(lockPadLeft, lockPadTop, lockPadRight - lockPadLeft, lockPadBottom - lockPadTop)); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); graphics.setStroke(new BasicStroke(1.0f)); graphics.fill(new Rectangle2D.Float(lockKeyholeLeft, lockKeyholeTop, lockKeyholeRight - lockKeyholeLeft, lockKeyholeBottom - lockKeyholeTop));
final int w = pSource.getWidth(); final int h = pSource.getHeight(); int newH = (int) Math.floor(h * cos + w * sin); AffineTransform transform = AffineTransform.getTranslateInstance((newW - w) / 2.0, (newH - h) / 2.0); transform.rotate(pAngle, w / 2.0, h / 2.0); Graphics2D g = dest.createGraphics(); try { g.transform(transform); if (!fast) { g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(new TexturePaint(pSource, new Rectangle2D.Float(0, 0, pSource.getWidth(), pSource.getHeight()))); g.fillRect(0, 0, pSource.getWidth(), pSource.getHeight());
@Override protected void paintImage(Graphics2D g2d, Color color) { Rectangle2D.Float path = new Rectangle2D.Float(); Dimension dimension = getDimension(); g2d.setStroke(new BasicStroke(16, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); g2d.scale(dimension.getHeight() / 128, dimension.getHeight() / 128); g2d.translate(40, 40); path.setRect(0, 0, 40, 40); g2d.setColor(color); Color bcolor = new Color(1f, 1f, 1f, 0f); g2d.setBackground(bcolor); g2d.fill(path); g2d.clearRect(16, 0, 8, 40); g2d.clearRect(0, 16, 40, 8); } }
public Icon getIcon() { ImageIcon icon = CsmImageLoader.getIcon(declaration); Image badge = getBadge(); if (badge == null) { BufferedImage img = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); Color transparent = new Color(0, 0, 0, 0); g2d.setColor(transparent); g2d.setComposite(AlphaComposite.Src); g2d.fill(new Rectangle2D.Float(0, 0, img.getWidth(), img.getHeight())); badge = img; } return ImageUtilities.image2Icon(ImageUtilities.mergeImages(icon.getImage(), badge, 16, 0)); }
private void fillWithWhiteBackground(final BufferedImage resizedImage) { Graphics2D g2d = resizedImage.createGraphics(); g2d.setColor(Color.LIGHT_GRAY); g2d.fill(new Rectangle2D.Float(0, 0, resizedImage.getWidth(), resizedImage.getHeight())); g2d.dispose(); }
private void drawBufferedImage(BufferedImage image, AffineTransform at) throws IOException graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite()); setClip(); AffineTransform imageTransform = new AffineTransform(at); PDSoftMask softMask = getGraphicsState().getSoftMask(); if( softMask != null ) imageTransform.scale(1, -1); imageTransform.translate(0, -1); Paint awtPaint = new TexturePaint(image, new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(), imageTransform.getScaleX(), imageTransform.getScaleY())); awtPaint = applySoftMaskToPaint(awtPaint, softMask); graphics.setPaint(awtPaint); Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1); if (isContentRendered()) graphics.fill(at.createTransformedShape(unitRect)); int width = image.getWidth(); int height = image.getHeight(); imageTransform.scale(1.0 / width, -1.0 / height); imageTransform.translate(0, -height);
graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite()); setClip(); AffineTransform prev = graphics.getTransform(); float yScale = Math.abs(m.getScalingFactorY()); AffineTransform transform = new AffineTransform(xform); transform.scale(1.0 / xScale, 1.0 / yScale); graphics.setTransform(transform); graphics.translate(0, image.getHeight()); graphics.scale(1, -1); new Rectangle2D.Float(0, 0, image.getWidth(), image.getHeight())); awtPaint = applySoftMaskToPaint(awtPaint, softMask); graphics.setPaint(awtPaint); graphics.fill( new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
private BufferedImage createBufferImageMetaTile( int rows, int columns, int height, int width, Color[][] colors) { Random random = new Random(); BufferedImage image = new BufferedImage(columns * width, rows * height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)); colors[i][j] = color; graphics.setColor(color); int x = j * width; int y = i * height; graphics.fill(new Rectangle2D.Float(x, y, width, height)); } } graphics.dispose(); return image; } }
protected void drawFrame(Graphics2D g2d) { Color trimColor = new Color(trimColorValue); Color controlColor = new Color(controlColorValue); g2d.setColor(trimColor); g2d.drawRect(3, 3, 8, 8); Rectangle2D rect = new Rectangle2D.Float(4, 4, 7, 7); GradientPaint gragient = new GradientPaint(4, 4, controlColor, 13, 13, trimColor); g2d.setPaint(gragient); g2d.fill(rect); }
if (Px.isIdentity() && (width != defaultWidth || height != defaultHeight)) { yscale = height / defaultHeight; float scale = Math.min(xscale, yscale); Px = AffineTransform.getScaleInstance(scale, scale); Rectangle2D aoi = (Rectangle2D) hints.get(KEY_AOI); aoi = Px.createTransformedShape(aoi).getBounds2D(); AffineTransform Mx = new AffineTransform(); double sx = width / aoi.getWidth(); double sy = height / aoi.getHeight(); Mx.scale(sx, sy); double tx = -aoi.getX(); double ty = -aoi.getY(); Mx.translate(tx, ty); curAOI = new Rectangle2D.Float(0, 0, width, height); Shape raoi = new Rectangle2D.Float(0, 0, width, height); renderer.repaint(curTxf.createInverse().createTransformedShape(raoi)); if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { Paint bgcolor = (Paint) hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR); g2d.setComposite(AlphaComposite.SrcOver); g2d.setPaint(bgcolor); g2d.fillRect(0, 0, w, h);
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D)g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int r = 5; RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width-1, height-1, r, r); Container parent = c.getParent(); if (parent!=null) { g2.setColor(parent.getBackground()); Area corner = new Area(new Rectangle2D.Float(x, y, width, height)); corner.subtract(new Area(round)); g2.fill(corner); } catch (NoClassDefFoundError | UnsatisfiedLinkError e) { LOGGER.error(e, e);
public synchronized BufferedImage replay( final int imageX, final int imageY ) { final BufferedImage image = new BufferedImage( imageX, imageY, BufferedImage.TYPE_INT_ARGB ); final Graphics2D graphics = image.createGraphics(); // clear the image area ... graphics.setPaint( new Color( 0, 0, 0, 0 ) ); graphics.fill( new Rectangle( 0, 0, imageX, imageY ) ); draw( graphics, new Rectangle2D.Float( 0, 0, imageX, imageY ) ); graphics.dispose(); return image; }
RenderedImage extract(int pageIndex, Float x, Float y, Float w, Float h) throws IOException { Rectangle2D rect = new Rectangle2D.Float(x, y, w, h); double scale = dpi / POINTS_IN_INCH; double bitmapWidth = rect.getWidth() * scale; double bitmapHeight = rect.getHeight() * scale; BufferedImage image = new BufferedImage((int)bitmapWidth, (int)bitmapHeight, BufferedImage.TYPE_INT_RGB); AffineTransform transform = AffineTransform.getScaleInstance(scale, scale); transform.concatenate(AffineTransform.getTranslateInstance(-rect.getX(), -rect.getY())); Graphics2D graphics = image.createGraphics(); graphics.setBackground(Color.WHITE); graphics.setTransform(transform); renderer.renderPageToGraphics(pageIndex, graphics); graphics.dispose(); return image; } }
private BufferedImage createImage() { IoParameters parameters = getParameters(); int width = parameters.getWidth(); int height = parameters.getHeight(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(Color.WHITE); jFreeChart.setTextAntiAlias(true); jFreeChart.setAntiAlias(true); if (jFreeChart.getLegend() != null) { jFreeChart.getLegend() .setFrame(BlockBorder.NONE); } jFreeChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
@Override public void draw(Graphics2D g) { final float wPage = (float) getPageSize().getWidth(); final float hPage = (float) getPageSize().getHeight(); final float wTile = Math.min(wPage/15f, hPage/15f); final float hTile = wTile; float w = wPage - wTile; float h = hPage - hTile; for (float y = (hPage - h)/2f; y < h; y += hTile) { float yRel = y/h; for (float x = (wPage - w)/2f; x < w; x += wTile) { float xRel = x/w; Color c = Color.getHSBColor(yRel, 1f, 1f); int alpha = 255 - (int) (xRel*255f); g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)); g.fill(new Rectangle2D.Float(x, y, wTile, hTile)); } } }
protected void build() throws SVGException { super.build(); StyleAttribute sty = new StyleAttribute(); // sty = getPres("unicode"); // if (sty != null) unicode = sty.getStringValue(); if (getPres(sty.setName("viewBox"))) { float[] dim = sty.getFloatList(); viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]); } if (viewBox == null) { // viewBox = super.getBoundingBox(); viewBox = new Rectangle(0, 0, 1, 1); } //Transform pattern onto unit square viewXform = new AffineTransform(); viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight()); viewXform.translate(-viewBox.getX(), -viewBox.getY()); }
/** * Glyph bounding boxes. */ @Override protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement) throws IOException { // draw glyph super.showGlyph(textRenderingMatrix, font, code, unicode, displacement); // bbox in EM -> user units Shape bbox = new Rectangle2D.Float(0, 0, font.getWidth(code) / 1000, 1); AffineTransform at = textRenderingMatrix.createAffineTransform(); bbox = at.createTransformedShape(bbox); // save Graphics2D graphics = getGraphics(); Color color = graphics.getColor(); Stroke stroke = graphics.getStroke(); Shape clip = graphics.getClip(); // draw graphics.setClip(graphics.getDeviceConfiguration().getBounds()); graphics.setColor(Color.RED); graphics.setStroke(new BasicStroke(.5f)); graphics.draw(bbox); // restore graphics.setStroke(stroke); graphics.setColor(color); graphics.setClip(clip); }