Java Image Resize getResizedImage(String path, int height, int width)

Here you can find the source of getResizedImage(String path, int height, int width)

Description

get Resized Image

License

Apache License

Declaration

public static Image getResizedImage(String path, int height, int width) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.ImageIcon;

public class Main {
    public static Image getResizedImage(String path, int height, int width) {
        Image img = new ImageIcon(path).getImage();
        return img.getScaledInstance(height, width, 0);
    }/*w  ww . ja  v  a 2  s. co  m*/

    public static Image getImage(InputStream stream) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        int a1;
        Image myImage = null;
        try {
            a1 = stream.read();
            while (a1 >= 0) {
                output.write((char) a1);
                a1 = stream.read();
            }
            myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray());
        } catch (IOException ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        } finally {
            try {
                output.close();
            } catch (IOException ex) {
                // TODO Auto-generated catch block
                ex.printStackTrace();
            }
        }

        return myImage;
    }
}

Related

  1. getResize(Image image, Dimension windowSize)
  2. getResizedImage(Image img, int iNewWidth, int iNewHeight)
  3. getResizedImage(Image original, final Integer w, final Integer h, boolean keepAspectRatio)
  4. getResizedImage(Image originalImage, Dimension newSize)
  5. getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType)
  6. resize(Image img, int newWidth, float quality)
  7. resize(String srcImageFile, String result, int newWidth, float quality)
  8. resizeImage(ImageIcon tmpIcon)
  9. resizeImage(String imagePath, int width, int height)