Java Code Examples for java.awt.RenderingHints#VALUE_INTERPOLATION_BICUBIC
The following examples show how to use
java.awt.RenderingHints#VALUE_INTERPOLATION_BICUBIC .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageUtils.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public static void scaleImageFile(File org, File dest, float scale) throws IOException { BufferedImage destImg = null; BufferedImage orgImg = ImageIO.read(org); if (orgImg != null) { Object interpolation; if (orgImg.getWidth() < 20) { interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; } else { interpolation = RenderingHints.VALUE_INTERPOLATION_BICUBIC; } destImg = scaleImage(Math.max(1, (int) (orgImg.getWidth() * scale)), Math.max(1, (int) (orgImg.getHeight() * scale)), orgImg, interpolation); ImageIO.write(destImg, org.getName().substring(org.getName().lastIndexOf('.') + 1), dest); } }
Example 2
Source File: RPlotPanel.java From visualvm with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { super.paint(g); int w = getWidth(); int h = getHeight(); if (renderingQuality != null && g instanceof Graphics2D) { Object interpolation = renderingQuality ? RenderingHints.VALUE_INTERPOLATION_BICUBIC : RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation); } Image img = offscreenImage; // not synchronized, createPlotImage() called from worker thread if (img != null && w > 0 && h > 0) g.drawImage(img, 0, 0, w, h, null); }
Example 3
Source File: GraphicsBox.java From lams with GNU General Public License v2.0 | 6 votes |
public GraphicsBox(BufferedImage image, float width, float height, float size, int interpolation) { this.image = image; this.width = width; this.height = height; this.scl = 1 / size; depth = 0; shift = 0; switch (interpolation) { case BILINEAR : interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; break; case NEAREST_NEIGHBOR : interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; break; case BICUBIC : interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; break; default : interp = null; } }
Example 4
Source File: ImageLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set interpolation * * @param value Interpolation */ public void setInterpolation(String value) { switch (value) { case "nearest": interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; break; case "bilinear": interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; break; case "bicubic": interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; break; } }
Example 5
Source File: AWTImageTools.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** Copies the source image into the target, applying scaling. */ public static BufferedImage copyScaled(final BufferedImage source, final BufferedImage target, Object hint) { if (hint == null) hint = RenderingHints.VALUE_INTERPOLATION_BICUBIC; final Graphics2D g2 = target.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); final double scalex = (double) target.getWidth() / source.getWidth(); final double scaley = (double) target.getHeight() / source.getHeight(); final AffineTransform xform = AffineTransform.getScaleInstance(scalex, scaley); g2.drawRenderedImage(source, xform); g2.dispose(); return target; }
Example 6
Source File: AffineTransformOp.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructs an {@code AffineTransformOp} given an affine transform. * The interpolation type is determined from the * {@code RenderingHints} object. If the interpolation hint is * defined, it will be used. Otherwise, if the rendering quality hint is * defined, the interpolation type is determined from its value. If no * hints are specified ({@code hints} is null), * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR * TYPE_NEAREST_NEIGHBOR}. * * @param xform The {@code AffineTransform} to use for the * operation. * * @param hints The {@code RenderingHints} object used to specify * the interpolation type for the operation. * * @throws ImagingOpException if the transform is non-invertible. * @see java.awt.RenderingHints#KEY_INTERPOLATION * @see java.awt.RenderingHints#KEY_RENDERING */ public AffineTransformOp(AffineTransform xform, RenderingHints hints){ validateTransform(xform); this.xform = (AffineTransform) xform.clone(); this.hints = hints; if (hints != null) { Object value = hints.get(RenderingHints.KEY_INTERPOLATION); if (value == null) { value = hints.get(RenderingHints.KEY_RENDERING); if (value == RenderingHints.VALUE_RENDER_SPEED) { interpolationType = TYPE_NEAREST_NEIGHBOR; } else if (value == RenderingHints.VALUE_RENDER_QUALITY) { interpolationType = TYPE_BILINEAR; } } else if (value == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) { interpolationType = TYPE_NEAREST_NEIGHBOR; } else if (value == RenderingHints.VALUE_INTERPOLATION_BILINEAR) { interpolationType = TYPE_BILINEAR; } else if (value == RenderingHints.VALUE_INTERPOLATION_BICUBIC) { interpolationType = TYPE_BICUBIC; } } else { interpolationType = TYPE_NEAREST_NEIGHBOR; } }
Example 7
Source File: AffineTransformOp.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Constructs an {@code AffineTransformOp} given an affine transform. * The interpolation type is determined from the * {@code RenderingHints} object. If the interpolation hint is * defined, it will be used. Otherwise, if the rendering quality hint is * defined, the interpolation type is determined from its value. If no * hints are specified ({@code hints} is null), * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR * TYPE_NEAREST_NEIGHBOR}. * * @param xform The {@code AffineTransform} to use for the * operation. * * @param hints The {@code RenderingHints} object used to specify * the interpolation type for the operation. * * @throws ImagingOpException if the transform is non-invertible. * @see java.awt.RenderingHints#KEY_INTERPOLATION * @see java.awt.RenderingHints#KEY_RENDERING */ public AffineTransformOp(AffineTransform xform, RenderingHints hints){ validateTransform(xform); this.xform = (AffineTransform) xform.clone(); this.hints = hints; if (hints != null) { Object value = hints.get(RenderingHints.KEY_INTERPOLATION); if (value == null) { value = hints.get(RenderingHints.KEY_RENDERING); if (value == RenderingHints.VALUE_RENDER_SPEED) { interpolationType = TYPE_NEAREST_NEIGHBOR; } else if (value == RenderingHints.VALUE_RENDER_QUALITY) { interpolationType = TYPE_BILINEAR; } } else if (value == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) { interpolationType = TYPE_NEAREST_NEIGHBOR; } else if (value == RenderingHints.VALUE_INTERPOLATION_BILINEAR) { interpolationType = TYPE_BILINEAR; } else if (value == RenderingHints.VALUE_INTERPOLATION_BICUBIC) { interpolationType = TYPE_BICUBIC; } } else { interpolationType = TYPE_NEAREST_NEIGHBOR; } }
Example 8
Source File: ImageLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get interpolation * * @return Interpolation */ public String getInterpolation() { if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) { return "bilinear"; } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) { return "bicubic"; } else { return "nearest"; } }
Example 9
Source File: ImageLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set interpolation string * * @param value Interpolation string */ public void setInterpolation(String value) { switch (value) { case "nearest": this.interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; break; case "bilinear": this.interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; break; case "bicubic": this.interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; break; } }
Example 10
Source File: ImageLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get interpolation string * * @return Interpolation string */ public String getInterpolationStr() { if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) { return "bilinear"; } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) { return "bicubic"; } else { return "nearest"; } }
Example 11
Source File: RasterLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set interpolation * * @param value Interpolation */ public void setInterpolation(String value) { switch (value) { case "nearest": interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; break; case "bilinear": interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; break; case "bicubic": interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; break; } }
Example 12
Source File: RasterLayer.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get interpolation * * @return Interpolation */ public String getInterpolation() { if (interp == RenderingHints.VALUE_INTERPOLATION_BILINEAR) { return "bilinear"; } else if (interp == RenderingHints.VALUE_INTERPOLATION_BICUBIC) { return "bicubic"; } else { return "nearest"; } }
Example 13
Source File: ImageShape.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set interpolation string * @param value Interpolation string */ public void setInterpolation(String value){ switch (value){ case "nearest": this.interp = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; break; case "bilinear": this.interp = RenderingHints.VALUE_INTERPOLATION_BILINEAR; break; case "bicubic": this.interp = RenderingHints.VALUE_INTERPOLATION_BICUBIC; break; } }
Example 14
Source File: LocalDocWriter.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
@Deprecated public static void createThumbsForDoc(TrpDoc doc, boolean overwrite) throws Exception { checkIfLocalDoc(doc); File thmbsDir = new File(doc.getMd().getLocalFolder().getAbsolutePath() + File.separator + LocalDocConst.THUMBS_FILE_SUB_FOLDER); FileUtils.forceMkdir(thmbsDir); int newHeight = LocalDocConst.THUMB_SIZE_HEIGHT; for (TrpPage p : doc.getPages()) { File imgFile = FileUtils.toFile(p.getUrl()); if (imgFile == null) throw new IOException("Cannot retrieve image url from: "+p.getUrl()); File thumbsFile = FileUtils.toFile(p.getThumbUrl()); if (thumbsFile == null) throw new IOException("Cannot retrieve thumbs url from: "+p.getThumbUrl()); if (thumbsFile.exists() && !overwrite) // skip if already there and overwrite not specified continue; logger.debug("creating thumb file: "+thumbsFile); long st = System.currentTimeMillis(); if (true) { } if (false) { BufferedImage originalImage = ImgUtils.readImage(imgFile); if (originalImage==null) throw new IOException("Cannot load image "+imgFile.getAbsolutePath()); double sf = (double)newHeight / (double)originalImage.getHeight(); int newWidth = (int)(sf * originalImage.getWidth()); BufferedImage thmbImg = new BufferedImage(newWidth, newHeight, originalImage.getType()); Graphics2D g = thmbImg.createGraphics(); RenderingHints rh = new RenderingHints( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHints(rh); g.drawImage(originalImage, 0, 0, newWidth, newHeight, null); g.dispose(); // logger.debug("thmbImg: "+originalImage+ " size: "+thmbImg.getWidth()+"x"+thmbImg.getHeight()); if (!ImageIO.write(thmbImg, FilenameUtils.getExtension(thumbsFile.getName()), thumbsFile)) throw new Exception("Could not write thumb file - no appropriate writer found!"); } logger.debug("created thumb file: "+thumbsFile.getAbsolutePath()+" time = "+(System.currentTimeMillis()-st)); } }
Example 15
Source File: ImageResize.java From openbd-core with GNU General Public License v3.0 | 4 votes |
private BufferedImage scaleToSize(BufferedImage img, int targetWidth, int targetHeight, Object interpolation) { if (targetWidth == img.getWidth() && targetHeight == img.getHeight()) { return img; } boolean higherQuality = ( // Set flag to use multi-step technique only if the // target size is less than 50% of the original size // and the interpolation mode is bilinear or bicubic (targetWidth < (int)(img.getWidth() * 0.5)) && ( (interpolation == RenderingHints.VALUE_INTERPOLATION_BILINEAR) || (interpolation == RenderingHints.VALUE_INTERPOLATION_BICUBIC) ) ); int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage ret = (BufferedImage) img; int w, h; if (higherQuality) { // Use multi-step technique: start with original size, then // scale down in multiple passes with drawImage() // until the target size is reached w = img.getWidth(); h = img.getHeight(); } else { // Use one-step technique: scale directly from original // size to target size with a single drawImage() call w = targetWidth; h = targetHeight; } do { if (higherQuality && w > targetWidth) { w /= 2; if (w < targetWidth) { w = targetWidth; } } if (higherQuality && h > targetHeight) { h /= 2; if (h < targetHeight) { h = targetHeight; } } BufferedImage tmp = new BufferedImage(w, h, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, interpolation ); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY ); g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2.drawImage(ret, 0, 0, w, h, null); g2.dispose(); ret = tmp; } while (w != targetWidth || h != targetHeight); return ret; }
Example 16
Source File: ScaledImageIcon.java From FlatLaf with Apache License 2.0 | 4 votes |
@Override public void paintIcon( Component c, Graphics g, int x, int y ) { /*debug g.setColor( Color.red ); g.drawRect( x, y, getIconWidth() - 1, getIconHeight() - 1 ); debug*/ // scale factor double systemScaleFactor = UIScale.getSystemScaleFactor( (Graphics2D) g ); float userScaleFactor = UIScale.getUserScaleFactor(); double scaleFactor = systemScaleFactor * userScaleFactor; // paint input image icon if not necessary to scale if( scaleFactor == 1 && iconWidth == imageIcon.getIconWidth() && iconHeight == imageIcon.getIconHeight() ) { imageIcon.paintIcon( c, g, x, y ); return; } // paint cached scaled icon if( systemScaleFactor == lastSystemScaleFactor && userScaleFactor == lastUserScaleFactor && lastImage != null ) { paintLastImage( g, x, y ); return; } // destination image size int destImageWidth = (int) Math.round( iconWidth * scaleFactor ); int destImageHeight = (int) Math.round( iconHeight * scaleFactor ); // get resolution variant of image if it is a multi-resolution image Image image = getResolutionVariant( destImageWidth, destImageHeight ); // size of image int imageWidth = image.getWidth( null ); int imageHeight = image.getHeight( null ); // scale image if necessary to destination size if( imageWidth != destImageWidth || imageHeight != destImageHeight ) { // determine scaling method; default is "quality" Object scalingInterpolation = RenderingHints.VALUE_INTERPOLATION_BICUBIC; float imageScaleFactor = (float) destImageWidth / (float) imageWidth; if( ((int) imageScaleFactor) == imageScaleFactor && imageScaleFactor > 1f && imageWidth <= 16 && imageHeight <= 16 ) { // use "speed" scaling for small icons if the scale factor is an integer // to avoid blurred icons scalingInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; } // scale image BufferedImage bufferedImage = image2bufferedImage( image ); image = scaleImage( bufferedImage, destImageWidth, destImageHeight, scalingInterpolation ); } // cache image lastSystemScaleFactor = systemScaleFactor; lastUserScaleFactor = userScaleFactor; lastImage = image; // paint image paintLastImage( g, x, y ); }
Example 17
Source File: BicubicResizer.java From youkefu with Apache License 2.0 | 2 votes |
/** * Instantiates a {@link BicubicResizer} with the specified rendering hints. * * @param hints Additional rendering hints to apply. */ public BicubicResizer(Map<RenderingHints.Key, Object> hints) { super(RenderingHints.VALUE_INTERPOLATION_BICUBIC, hints); }