Here you can find the source of GetImagenConTamanioDado(File file, int ancho, int alto)
public static BufferedImage GetImagenConTamanioDado(File file, int ancho, int alto)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import javax.swing.ImageIcon; public class Main { public static BufferedImage GetImagenConTamanioDado(File file, int ancho, int alto) { BufferedImage bi = null;/*w w w . ja v a2 s.co m*/ if (file.exists()) { String nombreFile = file.getName(); String extension = nombreFile.substring(nombreFile.indexOf(".")); if ((extension.endsWith("jpg") || extension.endsWith("JPG")) || (extension.endsWith("png") || extension.endsWith("PNG")) || (extension.endsWith("bmp") || extension.endsWith("BMP"))) { Image img = new ImageIcon(file.getAbsolutePath()).getImage(); int anchoOriginal = img.getWidth(null); int altoOriginal = img.getHeight(null); double anchoResultado = 1f * ancho / anchoOriginal; double altoResultado = 1f * alto / altoOriginal; int tipo = extension.compareToIgnoreCase(".jpg") == 0 || extension.compareToIgnoreCase(".bmp") == 0 ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; bi = new BufferedImage((int) (anchoOriginal * anchoResultado), (int) (altoOriginal * altoResultado), tipo); Graphics2D grph = (Graphics2D) bi.getGraphics(); grph.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); grph.scale(anchoResultado, altoResultado); grph.drawImage(img, 0, 0, null); grph.dispose(); } } return bi; } }