Skip to content

Instantly share code, notes, and snippets.

@undetected1
Created October 20, 2010 13:31
Show Gist options
  • Save undetected1/636404 to your computer and use it in GitHub Desktop.
Save undetected1/636404 to your computer and use it in GitHub Desktop.
// shrinking an image size on any magnitude
BufferedImage image = changeImageWidth(image, image.getWidth() / 2);
ConvolveOp gaussianFilter = getGaussianBlurFilter(BLUR_SIZE, true);
image = gaussianFilter.filter(image, null);
gaussianFilter = getGaussianBlurFilter(BLUR_SIZE, false);
image = gaussianFilter.filter(image, null);
ColorTintFilter colorMixFilter = new ColorTintFilter(Color.WHITE, 0.4f);
image = colorMixFilter.filter(image, null);
//yet another image operations....
// now bring it back!!!
image = changeImageWidth(image, image.getWidth() * 2);
public static BufferedImage changeImageWidth(BufferedImage image, int width) {
float ratio = (float) image.getWidth() / (float) image.getHeight();
int height = (int) (width / ratio);
BufferedImage temp = new BufferedImage(width, height,
image.getType());
Graphics2D g2 = temp.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null);
g2.dispose();
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment