Java进行时
      把握现在,成就未来!
posts - 23,comments - 30,trackbacks - 0

 

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 test {

    
public void jpgTset() throws Exception {
        File _file 
= new File("c:\\memo.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); //绘制缩小后的图
        
*/


        BufferedImage tag 
= new BufferedImage(wideth,height,BufferedImage.TYPE_INT_RGB);
        tag.getGraphics().drawImage(src,
0,0,wideth,height,null); 
        FileOutputStream out
=new FileOutputStream("c:\\youfilename.jpg"); //输出到文件流
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        encoder.encode(tag); 
//JPEG编码
        out.close();
    }


    
public static void main(String[] args){
        
try{
            
new test().jpgTset();
        }
catch(Exception e){
            e.printStackTrace();
    }


}

posted on 2008-09-26 13:55 biiau 阅读(4287) 评论(2)  编辑  收藏

FeedBack:
# re: JAVA复制图片
2009-09-21 10:37 | 3911
不错,转了  回复  更多评论
  
# re: JAVA复制图片[未登录]
2012-03-28 00:57 | 过客
非常感谢!  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: