Image resizing in Java

Image resizing to a ration of standard size (For Ex: 1024x800   to 800x600)

public void  resizeFile(File original,  int width, int height){

                int newWidth=0;
                int newHeight=0;
                BufferedImage bufferedImage =;      
                int orginalWidth=bufferedImage.getWidth();
                int orginalHeight=bufferedImage.getHeight();
                float ratioWidth= (float)orginalWidth/(float)width;
                float ratioHeight=(float)orginalHeight/(float)height;
                    newHeight= Math.round(orginalHeight/ratioWidth);
                    newWidth= Math.round(orginalWidth/ratioHeight);
// Now use these new newWidth and newHeight to write resized file........

Popular posts from this blog

Android: where to run keytool command in android

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine