AwtResourceBitmap(InputStream inputStream, float scaleFactor, int width, int height, int percent) throws IOException { super(inputStream); float[] newSize = GraphicUtils.imageSize(getWidth(), getHeight(), scaleFactor, width, height, percent); scaleTo((int) newSize[0], (int) newSize[1]); }
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); } }
throw new IOException("BitmapFactory failed to decodeStream"); float[] newSize = GraphicUtils.imageSize(bitmap.getWidth(), bitmap.getHeight(), scaleFactor, width, height, percent); if ((int) newSize[0] != bitmap.getWidth() || (int) newSize[1] != bitmap.getHeight()) bitmap = Bitmap.createScaledBitmap(bitmap, (int) newSize[0], (int) newSize[1], true);
public static android.graphics.Bitmap getResourceBitmap(InputStream inputStream, float scaleFactor, float defaultSize, int width, int height, int percent) throws IOException { try { // not in any cache, so need to render svg SVG svg = SVG.getFromInputStream(inputStream); Picture picture = svg.renderToPicture(); double scale = scaleFactor / Math.sqrt((picture.getHeight() * picture.getWidth()) / defaultSize); float[] bmpSize = GraphicUtils.imageSize(picture.getWidth(), picture.getHeight(), (float) scale, width, height, percent); android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap((int) Math.ceil(bmpSize[0]), (int) Math.ceil(bmpSize[1]), AndroidGraphicFactory.TRANSPARENT_BITMAP); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(picture, new RectF(0, 0, bmpSize[0], bmpSize[1])); return bitmap; } catch (Exception e) { throw new IOException(e); } }