public class ImageUtil extends Object
| 构造器和说明 |
|---|
ImageUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
compressImage(File sourceFile,
File targetPath)
压缩图像
|
static void |
compressImage(InputStream is,
OutputStream os)
压缩图像
BufferedImage read = ImageIO.read(new URL("http://qiniu.acyou.cn/images/13.jpg"));
BufferedImage bi = new BufferedImage(read.getWidth(), read.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(read, 0, 0, read.getWidth(), read.getHeight(), Color.LIGHT_GRAY, null);
g.dispose();
FileOutputStream os = new FileOutputStream("D:\\temp\\image\\123456.jpg");
ImageIO.write(bi, "jpg", os);
os.close();
|
static void |
compressImage(URL url,
File targetPath)
压缩图像
|
static ImageInfo |
getImageInfo(String source)
得到图片信息
|
public static void compressImage(URL url, File targetPath) throws Exception
url - urltargetPath - 目标路径Exception - 异常public static void compressImage(File sourceFile, File targetPath) throws Exception
sourceFile - 源文件targetPath - 目标路径Exception - 异常public static void compressImage(InputStream is, OutputStream os) throws Exception
BufferedImage read = ImageIO.read(new URL("http://qiniu.acyou.cn/images/13.jpg"));
BufferedImage bi = new BufferedImage(read.getWidth(), read.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(read, 0, 0, read.getWidth(), read.getHeight(), Color.LIGHT_GRAY, null);
g.dispose();
FileOutputStream os = new FileOutputStream("D:\\temp\\image\\123456.jpg");
ImageIO.write(bi, "jpg", os);
os.close();
is - 输入流os - 输出流Exception - 异常Copyright © 2022. All Rights Reserved.