public SVGDrawingPanel() { super(); svg = new SVGIcon(); svg.setScaleToFit(true); addComponentListener(this); }
@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); }
private void adaptSizeWithoutStretch(Dimension newSize){ int newW = (int) newSize.getWidth(); int newH = (int) newSize.getHeight(); float ratio = ((float)width)/height; float newRatio = ((float)newW)/newH; if(newRatio > ratio) newW = (int) (newH*ratio); else newH = (int) (newW/ratio); svg.setPreferredSize(new Dimension(newW, newH)); }
SVGIcon icon = new SVGIcon(); icon.setSvgURI(source.toURI()); icon.setAntiAlias(antiAlias); if (interpolation.equals("nearest neighbor")) icon.setInterpolation(SVGIcon.INTERP_NEAREST_NEIGHBOR); icon.setInterpolation(SVGIcon.INTERP_BILINEAR); icon.setInterpolation(SVGIcon.INTERP_BICUBIC); int iconWidth = width > 0 ? width : icon.getIconWidth(); int iconHeight = height > 0 ? height : icon.getIconHeight(); icon.setClipToViewbox(clipToViewBox); icon.setPreferredSize(new Dimension(iconWidth, iconHeight)); icon.setScaleToFit(sizeToFit); BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose();
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); } }
if (".svg".equals(fileName.substring(fileName.length() - 4).toLowerCase())) SVGIcon icon = new SVGIcon(); icon.setSvgURI(imageURL.toURI()); BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); ref = new SoftReference(img);
svgIcon = new SVGIcon(); svgIcon.setSvgURI(uri); svgIcon.setAntiAlias(true); this.svgInitialHeight = (double) svgIcon.getIconHeight(); this.svgInitialWidth = (double) svgIcon.getIconWidth();
double effectiveWidth = rect.getWidth(); double effectiveHeight = rect.getHeight(); svgIcon.setPreferredSize(new Dimension((int) (effectiveWidth + 0.5), (int) (effectiveHeight + 0.5))); fat.concatenate(AffineTransform.getTranslateInstance(-effectiveWidth / 2, -effectiveHeight / 2)); } else { double svgInitialWidth = svgIcon.getIconWidth(); double svgInitialHeight = svgIcon.getIconHeight(); 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); } catch (URISyntaxException e){
@Override public Image getImage() { BufferedImage bi = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); paintIcon(null, bi.getGraphics(), 0, 0); return bi; }
/** * Gets the {@code SVGIcon} associated to a particular parameter configuration. * @param map The input configuration. * @return The {@code SVGIcon} for the given configuration * @throws ParameterException If the given configuration can't be processed. */ public SVGIcon getSVGIcon(Map<String,Object> map) throws ParameterException { try { URI uri = new URI(url.getValue(map)); if(!svgCache.containsKey(uri)){ SVGIcon svgIcon = new SVGIcon(); svgIcon.setSvgURI(new URI(url.getValue(map))); svgIcon.setAntiAlias(true); svgCache.put(uri,svgIcon); } return svgCache.get(uri); } catch (URISyntaxException e) { throw new ParameterException("Can't process the input URI", e); } }
final int width = getIconWidth(); final int height = getIconHeight();
/** * 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); }
public Icon create() { icon.setAutosize(SVGIcon.AUTOSIZE_STRETCH); icon.setAntiAlias(isSvgAntialiasEnabled()); icon.setSvgURI(svgUri); return new CachingIcon(icon); }
/** * @param antiAlias true to use antiAliasing. * @deprecated */ public void setUseAntiAlias(boolean antiAlias) { setAntiAlias(antiAlias); }
/** * 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(); }
SVGIconCreator(URL url) { SVGUniverse svgUniverse = SVGCache.getSVGUniverse(); icon = new SVGIcon(); try { try { new URI(url.toString()); svgUri = svgUniverse.loadSVG(url); } catch (URISyntaxException ex) { svgUri = svgUniverse.loadSVG(url.openStream(), url.getPath()); } final SVGDiagram diagram = svgUniverse.getDiagram(svgUri); aspectRatio = diagram.getHeight() / diagram.getWidth(); } catch (Exception e) { throw new RuntimeException(e); } }
svg.setSvgURI(uri);
/** * @return true if antiAliasing is turned on. * @deprecated */ public boolean getUseAntiAlias() { return getAntiAlias(); }
/** * @deprecated */ public void setScaleToFit(boolean scaleToFit) { setAutosize(AUTOSIZE_STRETCH); // boolean old = this.scaleToFit; // this.scaleToFit = scaleToFit; // firePropertyChange("scaleToFit", old, scaleToFit); }
SVGIcon icon = new SVGIcon(); icon.setSvgURI(source.toURI()); icon.setAntiAlias(antiAlias); if (interpolation.equals("nearest neighbor")) icon.setInterpolation(SVGIcon.INTERP_NEAREST_NEIGHBOR); icon.setInterpolation(SVGIcon.INTERP_BILINEAR); icon.setInterpolation(SVGIcon.INTERP_BICUBIC); int iconWidth = width > 0 ? width : icon.getIconWidth(); int iconHeight = height > 0 ? height : icon.getIconHeight(); icon.setClipToViewbox(clipToViewBox); icon.setPreferredSize(new Dimension(iconWidth, iconHeight)); icon.setScaleToFit(sizeToFit); BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose();