1 Reply Latest reply: Jul 14, 2010 2:35 PM by 843802 RSS

    how to flush out the Tiff Image?

    843802
      This is code I am using. Each time the the tiff file on mt disk is updated by the other java class And I want to flush out the current Tiff Image and resources and show the new updated Tiff Image
       final File file = new File( filename );
              final SeekableStream stream = new FileSeekableStream( file );
       
              final TIFFDecodeParam param = null;
       
              final ImageDecoder dec = ImageCodec.createImageDecoder( "tiff", stream, param );
       
              // Which of the multiple images in the TIFF file do we want to load
              // 0 refers to the first, 1 to the second and so on.
              final int imageToLoad = 0;
       
              final RenderedImage renderedTiffChqImg =
                  new NullOpImage( dec.decodeAsRenderedImage( imageToLoad ), null, OpImage.OP_IO_BOUND, null );
       
              BufferedImage chqBufferedImg =
                  new BufferedImage( renderedTiffChqImg.getWidth(), renderedTiffChqImg.getHeight(),
                      BufferedImage.TYPE_BYTE_GRAY );
              chqBufferedImg = convertRenderedImgToBuffImg( renderedTiffChqImg );
              final JPanel addPanel = new JPanel();
              addPanel.setLayout( null );
              addPanel.setBounds( 100, 100, 800, 400 );
              add( addPanel );
       
              final ImageCanvas chqImgCanvas = new ImageCanvas( chqBufferedImg );
              chqImgCanvas.setBounds( 0, 0, 800, 600 );
       
              final Graphics g = chqBufferedImg.createGraphics();
              final int imageW = addPanel.getWidth();
              final int imageH = addPanel.getHeight();
              g.drawImage( chqBufferedImg, 0, 0, imageW, imageH, null, null );
       
              addPanel.add( chqImgCanvas );
        • 1. Re: how to flush out the Tiff Image?
          843802
          You'll need to reread the tiff file and create a new image each time the file changes. You won't be able to update any existing images with the new contents of the file.

          On a side note,
          BufferedImage chqBufferedImg =
              new BufferedImage( renderedTiffChqImg.getWidth(), renderedTiffChqImg.getHeight(),
                  BufferedImage.TYPE_BYTE_GRAY );
          chqBufferedImg = convertRenderedImgToBuffImg( renderedTiffChqImg );
          Doesn't this create an image which is then immediately discarded? It should read,
          BufferedImage chqBufferedImg = convertRenderedImgToBuffImg(renderedTiffChqImg);