我无法阅读tiff图像

时间:2014-07-31 05:11:56

标签: java jai

这是我的代码。我正在将图像粘贴到另一张图像上。这对于.gif和.jpg工作正常,但是在读取tiff图像时会出现Null Pointer Exception。

import java.awt.*;   
import java.awt.image.*;   
import java.io.*;     
import javax.media.jai.*; 
import javax.imageio.*;

public class Paint {   

    public static void main ( String args[] ) {   
        try {   
            // Create output file   
            OutputStream outStream = new FileOutputStream( "C:\\Users\\JavaPrg\\images\\image12.tif" );   

            // Load specified foreground and background    
            BufferedImage fgImage = ImageIO.read( new File( "C:\\Users\\JavaPrg\\images\\sign.png" ) );   
            BufferedImage bgImage = ImageIO.read( new File( "C:\\Users\\JavaPrg\\Input\\def.tif" ) );   


            BufferedImage tmpImage = new BufferedImage( fgImage.getWidth(), fgImage.getHeight(), BufferedImage.TYPE_INT_ARGB );   
            Graphics gOut = tmpImage.createGraphics();   

            // draw the foreground image on the temporary image   
            gOut.drawImage( fgImage, 0, 0, null );   
            gOut.dispose();   


            int width = tmpImage.getWidth();   
            int height = tmpImage.getHeight();   
            int[] pixels = new int[ width * height ];   
            pixels = tmpImage.getRGB( 0, 0, width, height, pixels, 0, width );   
            for ( int i = 0; i < pixels.length; i++ ) {   
                Color c = new Color( pixels[i] );   

                int r = c.getRed();   
                int g = c.getGreen();   
                int b = c.getBlue();   

                c = new Color( r, g, b);
                pixels[i] = c.getRGB();   
            }   
            tmpImage.setRGB( 0, 0, width, height, pixels, 0, width );   


            Graphics bgc = bgImage.createGraphics();   
            bgc.drawImage( tmpImage,1110 ,425 , null );   
            bgc.dispose();   

            // Save the new composite image   
            ImageIO.write( bgImage, "tif", outStream );   
            outStream.close();   
        }   
        catch ( Exception x ) {   
            x.printStackTrace();   
        }   
    }   
}  

无法发布截图: 它&#39; S Paint.main

中的java.lang.NullPointerException

0 个答案:

没有答案