private static int height;
private static BufferedImage img;
/**
-
强制压缩、放大
-
@param destFile
-
@param w
-
@param h
-
@throws IOException
*/
private static void resize(String destFile, int w, int h) throws IOException {
BufferedImage bufferedImage = new BufferedImage(w, h 《大厂前端面试题解析+Web核心总结学习笔记+企业项目实战源码+最新高清讲解视频》无偿开源 徽信搜索公众号【编程进阶路】 , BufferedImage.TYPE_INT_RGB);
bufferedImage.getGraphics().fillRect(0, 0, w, h);
bufferedImage.getGraphics().drawImage(img, 0, 0, w, h, null);//将原图片画到新图片上
//输出新图片
FileOutputStream out = new FileOutputStream(destFile);
ImageIO.write(bufferedImage, destFile.substring(destFile.lastIndexOf(‘.’) + 1), out);
out.close();
}
/**
-
按照固定的比例缩放图片
-
@param sourceFile 源图片
-
@param destFile 目标图片
-
@param scale 缩放比例
-
@throws IOException
*/
public static void resize(String sourceFile, String destFile, double scale) throws IOException {
img = ImageIO.read(new File(sourceFile));
width = img.getWidth();
height = img.getHeight();
int w = (int) (width * scale);
int h = (int) (height * scale);
resize(destFile, w, h);
}
/**
-
以高度为基准,等比例缩放图片
-
@param sourceFile 源图片
-
@param destFile 目标图片
-
@param h 作为基准的高度
-
@throws IOException
*/
public static void resizeByHeight(String sourceFile, String destFile, int h) throws IOException {
img = ImageIO.read(new File(sourceFile));
width = img.getWidth();
height = img.getHeight();
1029

被折叠的 条评论
为什么被折叠?



