List of usage examples for java.awt RenderingHints VALUE_INTERPOLATION_BILINEAR
Object VALUE_INTERPOLATION_BILINEAR
To view the source code for java.awt RenderingHints VALUE_INTERPOLATION_BILINEAR.
Click Source Link
From source file:org.openstreetmap.gui.jmapviewer.Tile.java
/** * Creates a image for the current Tile// w w w.j a v a2s. c o m * * @param image2 * origin * @param imageW * width for the tile * @param imageH * heigth for the tile */ private void createGraphicsFromImage(BufferedImage image2, int imageW, int imageH) { BufferedImage unScaledImage = image2; // Create new (blank) image of required (scaled) size BufferedImage scaledImage = new BufferedImage(imageW, imageH, BufferedImage.TYPE_INT_ARGB); image = scaledImage; // Paint scaled version of image to new image Graphics2D graphics2D = scaledImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(unScaledImage, 0, 0, imageW, imageH, null); // clean up graphics2D.dispose(); }
From source file:pl.datamatica.traccar.api.providers.ImageProvider.java
public byte[] getMarker(String name) throws IOException { if (!markerCache.containsKey(name)) { Image icon = getImage(name + ".png"); if (icon == null) return null; float l = 30f / 141, t = 28f / 189, r = 110f / 141, b = 108f / 189; int w = emptyMarker.getWidth(null), h = emptyMarker.getHeight(null); int tw = (int) Math.round((r - l) * w), th = (int) Math.round((b - t) * h); //https://stackoverflow.com/a/7951324 int wi = icon.getWidth(null), hi = icon.getHeight(null); while (wi >= 2 * tw || hi >= 2 * th) { if (wi >= 2 * tw) wi /= 2;/*from w w w. j a v a 2 s. c o m*/ if (hi >= 2 * th) hi /= 2; BufferedImage tmp = new BufferedImage(wi, hi, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(icon, 0, 0, wi, hi, null); g2.dispose(); icon = tmp; } BufferedImage marker = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = marker.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(emptyMarker, 0, 0, null); g.drawImage(icon, (int) Math.round(l * w), (int) Math.round(t * h), tw, th, null); g.dispose(); ByteArrayOutputStream boss = new ByteArrayOutputStream(); ImageIO.write((RenderedImage) marker, "png", boss); markerCache.put(name, boss.toByteArray()); } return markerCache.get(name); }
From source file:plugin.exporttokens.PortraitToken.java
/** * Generate a thumbnail image based on the character's portrait and * the thumnbnail rectangle./*from w w w . j a v a 2 s .co m*/ * * @param display The character being output. * @return The thumbnail image, or null if not defined. */ private BufferedImage generateThumb(CharacterDisplay display) { Rectangle cropRect = display.getPortraitThumbnailRect(); BufferedImage portrait = null; try { File file = new File(display.getPortraitPath()); if (file.isFile()) { portrait = ImageIO.read(file); } } catch (IOException ex) { Logging.errorPrint("Could not load image", ex); } if (portrait == null || cropRect == null) { return null; } BufferedImage thumb = portrait.getSubimage(cropRect.x, cropRect.y, cropRect.width, cropRect.height); thumb = getScaledInstance(thumb, Constants.THUMBNAIL_SIZE, Constants.THUMBNAIL_SIZE, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); return thumb; }
From source file:ro.nextreports.engine.exporter.ResultExporter.java
protected byte[] getScaledImage(InputStream is, String name, int width, int height) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*www. j a v a 2s. c o m*/ BufferedImage img = ImageIO.read(is); if ((img.getWidth() == width) && (img.getHeight() == height)) { // original width and height ImageIO.write(img, "png", baos); } else { int type = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : img.getType(); BufferedImage scaledImg = new BufferedImage(width, height, type); Graphics2D gScaledImg = scaledImg.createGraphics(); gScaledImg.setComposite(AlphaComposite.Src); gScaledImg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); gScaledImg.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); gScaledImg.drawImage(img, 0, 0, width, height, null); ImageIO.write(scaledImg, "png", baos); } } catch (IOException ex) { ex.printStackTrace(); LOG.error(ex.getMessage(), ex); throw new IOException("Image '" + name + "' could not be scaled."); } finally { is.close(); } return baos.toByteArray(); }
From source file:ro.nextreports.engine.exporter.ResultExporter.java
private BufferedImage toBufferedImage(Image src) { int w = src.getWidth(null); int h = src.getHeight(null); int type = BufferedImage.TYPE_INT_RGB; BufferedImage dest = new BufferedImage(w, h, type); Graphics2D g2 = dest.createGraphics(); g2.drawImage(src, 0, 0, null);/*from www. ja v a 2 s . c o m*/ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.dispose(); return dest; }
From source file:se.dibbler.backend.generics.DibblerImageUtil.java
private static Response<BufferedImage> resizeWithHint(BufferedImage originalImage, int type, int height, int width) { try {// w w w . j a v a 2 s. c o m BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, width, height, null); g.dispose(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return Response.success(resizedImage); } catch (Exception e) { LOG.error("[ ERROR when resizing file ] [ MESSAGE : {}]", e.getMessage()); return Response.error(GenericError.FILE_HANDLING); } }
From source file:util.ui.UiUtilities.java
/** * Convenience method that returns a scaled instance of the * provided {@code BufferedImage}./*from w w w. ja v a 2 s. co m*/ * * @param img the original image to be scaled * @param targetWidth the desired width of the scaled instance, * in pixels * @param targetHeight the desired height of the scaled instance, * in pixels * @return a scaled version of the original {@code BufferedImage} */ public static BufferedImage scaleDown(final BufferedImage img, final int targetWidth, final int targetHeight) { if (targetWidth > img.getWidth() || targetHeight > img.getHeight()) { return scaleIconToBufferedImage(img, targetWidth, targetHeight); } int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage result = img; int w = img.getWidth(); int h = img.getHeight(); do { w /= 2; if (w < targetWidth) { w = targetWidth; } h /= 2; if (h < targetHeight) { h = targetHeight; } BufferedImage tmp = new BufferedImage(w, h, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(result, 0, 0, w, h, null); g2.dispose(); result = tmp; } while (w != targetWidth || h != targetHeight); return result; }