Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use the 100% Java, Apache2 open source <a href="http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/">imgscalr library</a> (a single static class) and do something like this:</p> <pre><code>import org.imgscalr.Scalr.*; // static imports are awesome with the lib ... some class code ... // This is a super-contrived method name, I just wanted to incorporate // the details from your question accurately. public static void resizeImageTo600x600(BufferedImage image) { ImageIO.write(resize(image, 600), "JPG", new File("/path/to/file.jpg")); } </code></pre> <p><strong>NOTE</strong>: If the above looks odd, the static import allows me to use the <em>resize</em> call directly without specifying <em>Scalr.resize(...)</em></p> <p>Additionally, if the quality of the scaled image written out doesn't look good enough (it will be written out quickly though) you can use more arguments to the <em>resize</em> method like so:</p> <pre><code>public static void resizeImageTo600x600(BufferedImage image) { ImageIO.write(resize(image, Method.ULTRA_QUALITY, 600), "JPG", new File("/path/to/file.jpg")); } </code></pre> <p>.. and you can even apply a BufferedImageOp to the result to soften it incase the downscaling makes the image look to jaggy:</p> <pre><code>public static void resizeImageTo600x600(BufferedImage image) { ImageIO.write(resize(image, Method.ULTRA_QUALITY, 600, Scalr.OP_ANTIALIAS), "JPG", new File("/path/to/file.jpg")); } </code></pre> <p>You can start playing around with the library by just adding the following dep entry in your Maven POM (imgscalr is in the Maven central repo):</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.imgscalr&lt;/groupId&gt; &lt;artifactId&gt;imgscalr-lib&lt;/artifactId&gt; &lt;version&gt;4.2&lt;/version&gt; &lt;type&gt;jar&lt;/type&gt; &lt;scope&gt;compile&lt;/scope&gt; &lt;/dependency&gt; </code></pre>
 

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