⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageutil.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package cn.js.fan.util;import java.awt.image.*;import java.io.*;import javax.imageio.*;public class ImageUtil {        public static BufferedImage getScaleImage(BufferedImage source,                                              int width, int height) {                BufferedImage image = new BufferedImage(width, height, source.getType());        image.createGraphics().drawImage(source, 0, 0, width, height, null);        return image;    }        public static BufferedImage getScaleImage(BufferedImage source,                                              double xscale, double yscale) {                return getScaleImage(source,                (int)(source.getWidth() * xscale), (int)(source.getHeight() * yscale));    }        public static boolean scaleImage(File input, File output,                                     int width, int height) throws IOException {        BufferedImage image = ImageIO.read(input);        if (image == null) { return false; }        image = getScaleImage(image, width, height);        String name = output.getName();        String format = name.substring(name.lastIndexOf('.')+1).toLowerCase();        return ImageIO.write(image, format, output);    }        public static boolean scaleImage(File input, File output,                                     double xscale, double yscale) throws IOException {        BufferedImage image = ImageIO.read(input);        if (image == null) { return false; }        image = getScaleImage(image, xscale, yscale);        String name = output.getName();        String format = name.substring(name.lastIndexOf('.')+1).toLowerCase();        return ImageIO.write(image, format, output);    }        public static boolean Image2Thumb(File input, File output,                                     int thumbWidth) throws IOException {       BufferedImage image = ImageIO.read(input);       if (image == null) {           return false;       }       int w = image.getWidth();       int h = image.getHeight();        double dHeight = ((double)thumbWidth)/w * h;        int height = (int)dHeight;        if (w>thumbWidth)            image = getScaleImage(image, thumbWidth, height);        else            image = getScaleImage(image, w, h);        String name = output.getName();        String format = name.substring(name.lastIndexOf('.')+1).toLowerCase();        return ImageIO.write(image, format, output);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -