@Override public void paintComponent(Graphics g) { try{ super.paintComponent(g); } catch (Exception e){} final int width = getWidth(); final int height = getHeight(); g.setColor(getBackground()); //g.fillRect(0, 0, width, height); svg.setAntiAlias(true); svg.paintIcon(this, g, 0, 0); }
public static BufferedImage getResourceBitmap(InputStream inputStream, String name, float scaleFactor, float defaultSize, int width, int height, int percent) throws IOException { try { URI uri = SVGCache.getSVGUniverse().loadSVG(inputStream, name); SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); double scale = scaleFactor / Math.sqrt((diagram.getHeight() * diagram.getWidth()) / defaultSize); float[] bmpSize = GraphicUtils.imageSize(diagram.getWidth(), diagram.getHeight(), (float) scale, width, height, percent); SVGIcon icon = new SVGIcon(); icon.setAntiAlias(true); icon.setAutosize(SVGIcon.AUTOSIZE_STRETCH); icon.setPreferredSize(new Dimension((int) bmpSize[0], (int) bmpSize[1])); icon.setSvgURI(uri); BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, bufferedImage.createGraphics(), 0, 0); return bufferedImage; } catch (Exception e) { throw new IOException(e); } }
/** * Draws the icon to the specified component. * @param comp - Component to draw icon to. This is ignored by SVGIcon, and can be set to null; only gg is used for drawing the icon * @param gg - Graphics context to render SVG content to * @param x - X coordinate to draw icon * @param y - Y coordinate to draw icon */ public void paintIcon(Component comp, Graphics gg, int x, int y) { //Copy graphics object so that Graphics2D g = (Graphics2D)gg.create(); paintIcon(comp, g, x, y); g.dispose(); }
/** * Draws the icon to the specified component. * @param comp - Component to draw icon to. This is ignored by SVGIcon, and can be set to null; only gg is used for drawing the icon * @param gg - Graphics context to render SVG content to * @param x - X coordinate to draw icon * @param y - Y coordinate to draw icon */ @Override public void paintIcon(Component comp, Graphics gg, int x, int y) { //Copy graphics object so that Graphics2D g = (Graphics2D)gg.create(); paintIcon(comp, g, x, y); g.dispose(); }
/** * Draws the icon to the specified component. * @param comp - Component to draw icon to. This is ignored by SVGIcon, and can be set to null; only gg is used for drawing the icon * @param gg - Graphics context to render SVG content to * @param x - X coordinate to draw icon * @param y - Y coordinate to draw icon */ @Override public void paintIcon(Component comp, Graphics gg, int x, int y) { //Copy graphics object so that Graphics2D g = (Graphics2D)gg.create(); paintIcon(comp, g, x, y); g.dispose(); }
@Override public Image getImage() { BufferedImage bi = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); paintIcon(null, bi.getGraphics(), 0, 0); return bi; }
@Override public Image getImage() { BufferedImage bi = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); paintIcon(null, bi.getGraphics(), 0, 0); return bi; }
/** * Draw the svg linked to this {@code Onlineresource} in the Graphics2D g2. * @param g2 * @param at * @param opacity */ public void drawSVG(Graphics2D g2, AffineTransform at, double opacity) { AffineTransform fat = new AffineTransform(at); if (effectiveHeight != null && effectiveWidth != null) { svgIcon.setPreferredSize(new Dimension((int) (effectiveWidth + 0.5), (int) (effectiveHeight + 0.5))); fat.concatenate(AffineTransform.getTranslateInstance(-effectiveWidth / 2, -effectiveHeight / 2)); } else { svgIcon.setPreferredSize(new Dimension((int) (svgInitialWidth + 0.5), (int) (svgInitialHeight + 0.5))); fat.concatenate(AffineTransform.getTranslateInstance(-svgInitialWidth / 2, -svgInitialHeight / 2)); } svgIcon.setScaleToFit(true); AffineTransform atMedia = new AffineTransform(g2.getTransform()); g2.transform(fat); svgIcon.paintIcon((Component) null, g2, 0, 0); g2.setTransform(atMedia); }
icon.paintIcon(null, g, 0, 0); g.dispose(); ref = new SoftReference(img);
icon.paintIcon(null, g, 0, 0); g.dispose(); ref = new SoftReference(img);
icon.paintIcon(null, g, 0, 0); g.dispose(); ref = new SoftReference<BufferedImage>(img);
icon.paintIcon(null, g, 0, 0); g.dispose(); ref = new SoftReference<BufferedImage>(img);
g2.transform(fat); svgIcon.paintIcon((Component) null, g2, 0, 0); g2.setTransform(atMedia); } catch (URISyntaxException e){
icon.paintIcon(null, g, 0, 0); g.dispose();
icon.paintIcon(null, g, 0, 0); g.dispose();
icon.paintIcon(null, g, 0, 0); g.dispose();
icon.paintIcon(null, g, 0, 0); g.dispose();
g2.addRenderingHints(mt.getRenderingHints()); icon.paintIcon((Component) null, g2, 0, 0); return img;
icon.setSvgURI(uri); BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, bufferedImage.createGraphics(), 0, 0);