![]() ![]() Mentioned in Chris Campbell's blog about scaling in Java, progressive scaling is basically incrementally scaling an image in smaller steps until the final dimensions are reached. Nobel's implementation is about 8 times slower than a 1/2 step progressive scaling algorithm with Graphics2d. The downside is that it usually is very slow without any highly optimized or hardware accelerated implementations known to me. The lib is published on maven-central which is not mentioned, unfortunately. tFilter(ResampleFilters.getLanczos3Filter()) īufferedImage scaledImage = resizeOp.filter(imageToScale, null) A simple example using said lib: ResampleOp resizeOp = new ResampleOp(dWidth, dHeight) Unfortunately there is no native implementation in current JDK so you either implement it yourself and use a lib like Morten Nobel's lib. Is said to be good for up- and especially downscaling. Unfortunately a single image is not enough to judge a scaling algorithm, you should test icons with sharp edges, photos with text, etc. Graphics2d Nearest Neighbor interpolation.Morten Nobel's lib Bilinear Progressive Scaling.Imgscalr QUALTY (1/2 step Bicubic Progressive Scaling).Imgscalr ULTRA_QUALTY (1/7 step Bicubic Progressive Scaling).Thumbnailator Bilinear Progressive Scaling.Here is your image scaled to 96x140 with different methods/libs. One-Step scaling for up scaling (with Graphics2d bicubic fast and good results, usually not as good as Lanczos3)Įxamples for every method can be found in this answer.Progressive Down Scaling (usually visually fine, can be quite fast).Lanczos3 Resampling (usually visually better, but slower).Among others, here are the methods I recommend for scaling: Unfortunately, there is no recommended out-of-the-box scaling in Java that provides visually good results. Is there anyway to increase the quality of the program output so I don't have to manually resize all photos? UPDATE: No significant difference using BICUBIC This is the manual resizing I've done in Microsoft Paint:Īnd this is the output from my program : Graphics2D.drawImage(image, 0, 0, width, height, null) tRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON) tRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY) tRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR) Public static void main(String args) throws IOException while (width != targetw || height != targeth) įinal BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) įinal Graphics2D graphics2D = bufferedImage.createGraphics() * This class will resize all the images in a given folder Unfortunately, the quality of the image is poorly lost and I don't have access to the uncompressed images. I have 10,000 photos that need to be resized so I have a Java program to do that.
0 Comments
Leave a Reply. |