I have a BufferedImage which is quite tall (something like 1100 pixels height) and not especially wide (maybe 200-300 pixels). The image consists of a data plot, but most of the pixels represents a background color/value that's not really interesting. My problem is that when the image is resized from a height of 1100 px to something like 200-300 px, many of the pixels that actually contained interesting data is trashed by background color pixels. Is there any way to tell the Java 2D rescaling algorithms that I prefer pixels of certain values (or better, that I want to down-prioritize the background color) while rescaling? I use the following code snippet to rescale the image:
BufferedImage resized = new BufferedImage(width, height, imageType);
Graphics2D graphics2D = resized.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); //Has worked best in my case
graphics2D.drawImage(source, 0, 0, width, height, null);
graphics2D.dispose();
I'm sure that there's more effective ways of resizing images in Java, but that's not interesting (at least not for now).
A kind of boring thing is that I used a library before (which will not be used anymore) that actually managed to keep much of the valuable data representing pixels.
Note that I have the raw pixel data at hand (a 2D int array) if that is of any help. The application will handle many images of different sizes, so I don't know for sure that the height necessarily is 1100 pixels.
Thanks.