Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep/favor certain pixel values when resizing a tall BufferedImage?
    text
    copied!<p>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:</p> <pre><code>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(); </code></pre> <p>I'm sure that there's more effective ways of resizing images in Java, but that's not interesting (at least not for now).</p> <p>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.</p> <p>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.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload