List of utility methods to do Image Resize
double[] | getResize(Image image, Dimension windowSize) get Resize double w = image.getWidth(null); double h = image.getHeight(null); double f = 1; double fw = w / windowSize.getWidth(); double fh = h / windowSize.getHeight(); if (fw > 1 || fh > 1) { if (fh > fw) { w /= fh; ... |
ImageIcon | getResizedImage(Image img, int iNewWidth, int iNewHeight) Image resizes if (img == null) { return null; ImageIcon iiNew = new ImageIcon(); Image scaleImg = img.getScaledInstance(iNewWidth, iNewHeight, Image.SCALE_AREA_AVERAGING); iiNew.setImage(scaleImg); return iiNew; |
Image | getResizedImage(Image original, final Integer w, final Integer h, boolean keepAspectRatio) get Resized Image if (original == null) throw new IllegalArgumentException("Original image cannot be null."); if (w == null && h == null) return original; final int currentW = original.getWidth(null); final int currentH = original.getHeight(null); float ratio; int converted; ... |
BufferedImage | getResizedImage(Image originalImage, Dimension newSize) Get a resized image. BufferedImage bImage = new BufferedImage(newSize.width, newSize.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bImage.createGraphics(); g2d.drawImage(originalImage, null, null); g2d.dispose(); return bImage; |
Image | getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType) Scales the specified image to the desired dimensions by specified type and the smooth scaling method return getResizedImage(originalImage, newWidth, newHeight, imageType, Image.SCALE_SMOOTH);
|
Image | getResizedImage(String path, int height, int width) get Resized Image Image img = new ImageIcon(path).getImage(); return img.getScaledInstance(height, width, 0); |
Image | resize(Image img, int newWidth, float quality) resize if (quality < 0 || quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); ImageIcon ii = new ImageIcon(img); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); ... |
void | resize(String srcImageFile, String result, int newWidth, float quality) resize File originalFile = new File(srcImageFile); if (quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath()); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); ... |
ImageIcon | resizeImage(ImageIcon tmpIcon) resize Image if (tmpIcon != null) { if (tmpIcon.getIconWidth() > 90) { tmpIcon = new ImageIcon(tmpIcon.getImage().getScaledInstance(100, -1, Image.SCALE_DEFAULT)); return tmpIcon; |
ImageIcon | resizeImage(String imagePath, int width, int height) Method to resize and visualize the user selected image within the image label ImageIcon ic = new ImageIcon(imagePath); Image img = ic.getImage(); Image newImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); return new ImageIcon(newImage); |