2013年6月27日 星期四

java - read - wite - Image - gray

    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
    BufferedImage img=null;
    BufferedImage img2=null;
       
    int w,h;
   
   
        try{
           
            img = ImageIO.read(new File("IMG_5277.JPG"));       

            w = img.getWidth(null);
            h = img.getHeight(null);
       

            img2 =new BufferedImage(w,h,BufferedImage.TYPE_BYTE_GRAY);
            Graphics2D g2d = img2.createGraphics();
            g2d.drawImage(img,0,0,null);        
       

        File outputfile = new File("saved2.jpg");
        ImageIO.write(img2, "jpg", outputfile);
       
    }
    catch(IOException e){
       
    }

       
    }

沒有留言:

張貼留言