使用java将网页保存为mht格式(1)
2009-03-12 21:20
435 查看
import java.io.*; import java.awt.*; import java.awt.image.*; import com.sun.image.codec.jpeg.*; public class ImageUtil { private String srcFile; private String destFile; private int width; private int height; private Image img; public ImageUtil(String srcFile) throws IOException { File _file = new File(srcFile); this.srcFile = srcFile; this.destFile = srcFile; img = javax.imageio.ImageIO.read(_file); width = img.getWidth(null); height = img.getHeight(null); } public void resize(int w, int h) throws IOException { BufferedImage _image = new BufferedImage(w, h,BufferedImage.TYPE_INT_RGB); _image.getGraphics().drawImage(img, 0, 0, w, h, null); FileOutputStream out = new FileOutputStream(destFile); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(_image); out.close(); } public void resize(double t) throws IOException { int w = (int) (width * t); int h = (int) (height * t); resize(w, h); } public void resizeByWidth(int w) throws IOException { int h = (int) (height * w / width); resize(w, h); } public void resizeByHeight(int h) throws IOException { int w = (int) (width * h / height); resize(w, h); } public void resizeFix(int w, int h) throws IOException { if (width / height > w / h) { resizeByWidth(w); } else { resizeByHeight(h); } } public int getSrcWidth() { return width; } public int getSrcHeight() { return height; } }
相关文章推荐
- 使用java将网页保存为mht格式
- 硬盘浏览程序,保存成网页格式便可使用
- 使用vbs自动化批量保存网页为mht_V1
- 使用python和java两种方式来完成下载网页,并保存成文件,
- 保存网页的html和mht格式的玄机
- 下载网页后保存为mht格式的文件
- 使用TWebBrowser组件保存网页为html和mht文件 收藏
- chrome保存网页为单个文件(mht格式)
- 硬盘浏览程序,保存成网页格式便可使用
- Java使用utf8格式保存文本文件的方法
- 使用TWebBrowser组件保存网页为html和mht文件
- Chrome如何保存mht格式网页
- 使用TWebBrowser组件保存网页为html和mht文件 收藏
- 使用Chrome保存网页为mht文件
- Java中Calendar类的简单使用方法,以及日期格式化的方法,字符串日期格式的验证
- Java 使用Zip进行多文件保存和读取
- Python MOOC简单获取网页内容并以html格式保存在本地
- java中使用输出流下载文件弹出打开保存框
- C#代码实现把网页文件保存为mht文件
- JAVA在线抓取网页中的元素的例子(使用JSoup包进行解析)