站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题java读取图片长宽问题

java读取图片长宽问题

摘要: java读取图片长宽问题

</td> </tr> <tr> <td width="553" height="35" valign="top" class="ArticleTeitle"> import java.io.File;
import java.io.FileOutputStream;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class JpgTest {

public void jpgTset() throws Exception{
File _file = new File("1.jpg"); //读入文件
Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
int wideth=src.getWidth(null); //得到源图宽
int height=src.getHeight(null); //得到源图长
BufferedImage tag = new BufferedImage(wideth/2,height/2,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,wideth/2,height/2,null); //绘制缩小后的图
FileOutputStream out=new FileOutputStream("newfile.jpg"); //输出到文件流
// File file = new File("newFile.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag); //JPEG编码
out.close();
}

public static void main(String[] args){
try{
new JpgTest().jpgTset();
}catch(Exception e){
e.printStackTrace();
}
}
}
</td> <td width="172" valign="top" class="ArticleTeitle">
</td> </tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">


↑返回目录
前一篇: 飘扬的旗帜
后一篇: HTML标记过滤