1
回答
java图片操作方法
注册华为云得mate10,2.9折抢先购!>>>   
public static File createImage(File imageFile, String imageFormat) {  
        File tempFile = null;  
        try {  
            Iterator readers = ImageIO.getImageReadersByFormatName(imageFormat);  
            ImageReader reader = (ImageReader)readers.next();  
          
            ImageInputStream iis = ImageIO.createImageInputStream(imageFile);  
            reader.setInput(iis);  
            //Read the stream metadata  
            IIOMetadata streamMetadata = reader.getStreamMetadata();  
              
            //Set up the writeParam  
            TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.CHINESE);  
            tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);  
              
            //Get tif writer and set output to file  
            Iterator writers = ImageIO.getImageWritersByFormatName("tiff");  
            ImageWriter writer = (ImageWriter)writers.next();  
              
            BufferedImage bi = reader.read(0);  
            IIOImage image = new IIOImage(bi,null,reader.getImageMetadata(0));  
            tempFile = tempImageFile(imageFile);  
            ImageOutputStream ios = ImageIO.createImageOutputStream(tempFile);  
            writer.setOutput(ios);  
            writer.write(streamMetadata, image, tiffWriteParam);  
            ios.close();  
              
            writer.dispose();  
            reader.dispose();  
              
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
        return tempFile;  
    }  


这个方法是什么意思

<无标签>
举报
ForTheFree
发帖于2年前 1回/274阅
顶部