Java Code Examples for java.awt.RenderingHints#VALUE_INTERPOLATION_BILINEAR

The following examples show how to use java.awt.RenderingHints#VALUE_INTERPOLATION_BILINEAR . 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: ImageContext.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Return the interpolation rendering hint to use. This will not return
 * null. If this is undefined, then the antialiasing and rendering hints are
 * consulted (which will return either NEAREST_NEIGHBOR or BILINEAR). If
 * nothing is defined then this returns BILINEAR.
 */
protected Object getInterpolationRenderingHint() {
	Object v = renderingHints.get(RenderingHints.KEY_INTERPOLATION);
	if (v != null)
		return v;

	v = renderingHints.get(RenderingHints.KEY_ANTIALIASING);
	if (RenderingHints.VALUE_ANTIALIAS_ON.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else if (RenderingHints.VALUE_ANTIALIAS_OFF.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}

	v = renderingHints.get(RenderingHints.KEY_RENDERING);
	if (RenderingHints.VALUE_RENDER_QUALITY.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else if (RenderingHints.VALUE_RENDER_SPEED.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}

	// nothing is defined:
	return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
}
 
Example 2
Source File: GraphicsBox.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: ImageScaling.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
public ImageScaling(String scalingTypeParameter, String scalingSizeParameter) {
	higherQuality = false;
	targetSize = 1024 * 768;
	if (scalingSizeParameter != null) {
		targetSize = Integer.parseInt(scalingSizeParameter);
	}
	hint = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	if (scalingTypeParameter.equals("nn")) {
		hint = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}
}
 
Example 4
Source File: ImageDrawer.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
private Object getRenderingHint(Graphics2D g2d) {
	if (g2d.getTransform().getScaleX() < 1.0f) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}
}
 
Example 5
Source File: ImageDrawer.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
private Object getRenderingHint(Graphics2D g2d) {
	if (g2d.getTransform().getScaleX() < 1.0f) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}
}
 
Example 6
Source File: AffineTransformOp.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 9
Source File: ImageLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 10
Source File: ImageLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 11
Source File: ImageLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 12
Source File: RasterLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: RasterLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 14
Source File: ImageShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 15
Source File: NullResizer.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates the {@code NullResizer} which draws the source image at
 * the origin of the destination image.
 */
public NullResizer()
{
	this(
			RenderingHints.VALUE_INTERPOLATION_BILINEAR,
			Collections.<Key, Object>emptyMap()
	);
}
 
Example 16
Source File: ImageResize.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
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 17
Source File: ImageScaling.java    From multimedia-indexing with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor with no arguments, all fields take the default values
 */
public ImageScaling() {
	targetSize = 1024 * 768;
	higherQuality = true;
	hint = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
}
 
Example 18
Source File: ImageScaling.java    From multimedia-indexing with Apache License 2.0 4 votes vote down vote up
public ImageScaling(int targetSize) {
	this.targetSize = targetSize;
	higherQuality = true;
	hint = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
}
 
Example 19
Source File: ProgressiveBilinearResizer.java    From youkefu with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a {@link ProgressiveBilinearResizer} with the specified
 * rendering hints.
 * 
 * @param hints		Additional rendering hints to apply.
 */
public ProgressiveBilinearResizer(Map<RenderingHints.Key, Object> hints)
{
	super(RenderingHints.VALUE_INTERPOLATION_BILINEAR, hints);
}
 
Example 20
Source File: BilinearResizer.java    From youkefu with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a {@link BilinearResizer} with the specified rendering
 * hints.
 * 
 * @param hints		Additional rendering hints to apply.
 */
public BilinearResizer(Map<RenderingHints.Key, Object> hints)
{
	super(RenderingHints.VALUE_INTERPOLATION_BILINEAR, hints);
}