Bufferedimage resize

Updated answer I cannot recall why my original answer worked but having tested it in a separate environment, I agree, the original accepted answer doesn’t work (why I said it did I cannot remember either). This, on the other hand, did work: public static BufferedImage resize(BufferedImage img, int newW, int newH) { Image tmp = … Read more

How to scale a BufferedImage

AffineTransformOp offers the additional flexibility of choosing the interpolation type. BufferedImage before = getBufferedImage(encoded); int w = before.getWidth(); int h = before.getHeight(); BufferedImage after = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); AffineTransform at = new AffineTransform(); at.scale(2.0, 2.0); AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); after = scaleOp.filter(before, after); The fragment shown illustrates resampling, not cropping; this related … Read more

Java – resize image without losing quality

Unfortunately, there is no recommended out-of-the-box scaling in Java that provides visually good results. Among others, here are the methods I recommend for scaling: Lanczos3 Resampling (usually visually better, but slower) Progressive Down Scaling (usually visually fine, can be quite fast) One-Step scaling for up scaling (with Graphics2d bicubic fast and good results, usually not … Read more

Java converting Image to BufferedImage

From a Java Game Engine: /** * Converts a given Image into a BufferedImage * * @param img The Image to be converted * @return The converted BufferedImage */ public static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } // Create a buffered image with transparency BufferedImage bimage = new … Read more

Java – get pixel array from image

I was just playing around with this same subject, which is the fastest way to access the pixels. I currently know of two ways for doing this: Using BufferedImage’s getRGB() method as described in @tskuzzy’s answer. By accessing the pixels array directly using: byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData(); If you are working with large images … Read more