import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.*;
import com.sun.image.codec.jpeg.JPEGCodec.*;
import com.sun.image.codec.jpeg.JPEGImageEncoder.*;
public class ZoomImage {
public void zoom(String file1,String file2){
try{
//读入图片文件
File _file=new File(file1);
Image src=javax.imageio.ImageIO.read(_file); //构造Image对象
int width=src.getWidth(null);
int height=src.getHeight(null);
//图片缩放
BufferedImage tag=new BufferedImage(width/2,height/2,BufferedImage.TYPE_INT_RGB);
//缩小后的图片
tag.getGraphics().drawImage(src, 0, 0, width/2, height/2, null);
//写入图片
FileOutputStream out=new FileOutputStream(file2);
//输出到文件流,进行JPEG编码
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}catch(Exception e){}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}下面提示出错: JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);提示内容:Multiple markers at this line - JPEGCodec cannot be resolved - JPEGImageEncoder cannot be resolved to a type
添加回答
举报
0/150
提交
取消