JAI - problem displaying additional pages from multi-page image
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sam_Patel
Posted On:   Monday, May 20, 2002 08:36 AM

Hi, I have 10 page multipage tiff images. And i would like to show the images one-by-one on a ScrollingImagePanel. I have a Main frame with two panels. Panel1 which shows the ScrollingImagePanel. And Panel2 has two buttons. LOAD Button show the 1st page on the ScrollingImagePanel. And NEXT button is suppose to show the 2nd page and continue until the end of the multipage images. I am having problem with the NEXT button. I wrote something which show the page number and page height on the output screen. It shows the page# and different heights each time you hit the NEXT Button. But it would not show the images on the ScrollingImagePanel. It just shows the 1st page. I would appreciate if you can help me out   More>>

Hi,
I have 10 page multipage tiff images. And i would like to show the images one-by-one on a ScrollingImagePanel.
I have a Main frame with two panels. Panel1 which shows the ScrollingImagePanel.
And Panel2 has two buttons. LOAD Button show the 1st page on the ScrollingImagePanel.
And NEXT button is suppose to show the 2nd page and continue until the end of the multipage images.
I am having problem with the NEXT button. I wrote something which show the page number and page height
on the output screen. It shows the page# and different heights each time you hit the NEXT Button. But it would not show the images on the ScrollingImagePanel.
It just shows the 1st page. I would appreciate if you can help me out with this problom.

Please find the code which is written in JBuilder.




// Main class


package untitled1;


import java.awt.*;

import javax.swing.UIManager;

import java.awt.*;


import java.io.File;

import java.io.IOException;

import java.awt.Frame;

import java.awt.image.RenderedImage;

import javax.media.jai.widget.ScrollingImagePanel;

import javax.media.jai.NullOpImage;

import javax.media.jai.OpImage;

import com.sun.media.jai.codec.SeekableStream;

import com.sun.media.jai.codec.FileSeekableStream;

import com.sun.media.jai.codec.TIFFDecodeParam;

import com.sun.media.jai.codec.ImageDecoder;

import com.sun.media.jai.codec.ImageCodec;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.event.*;


public class Application1 {


boolean packFrame = false;


//Construct the application


public Application1() {

Frame2 frame = new Frame2();

frame.setSize(820,700);

//Validate frames that have preset sizes

//Pack frames that have useful preferred size info, e.g. from their layout

if (packFrame) {

frame.pack();

}

else {

frame.validate();

}

//Center the window

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

frame.setVisible(true);

}

//Main method

public static void main(String[] args) {



new Application1();



}





}



********************************************************************************

// Frame2 Class



package untitled1;



import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.UIManager;

import java.io.File;

import java.io.IOException;

import java.awt.Frame;

import java.awt.image.RenderedImage;

import javax.media.jai.widget.ScrollingImagePanel;

import javax.media.jai.NullOpImage;

import javax.media.jai.OpImage;

import com.sun.media.jai.codec.SeekableStream;

import com.sun.media.jai.codec.FileSeekableStream;

import com.sun.media.jai.codec.TIFFDecodeParam;

import com.sun.media.jai.codec.ImageDecoder;

import com.sun.media.jai.codec.ImageCodec;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.event.*;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.*;

import javax.media.jai.widget.*;

import com.sun.media.jai.codec.*;

import java.util.*;

/**

*

Title:



*

Description:



*

Copyright: Copyright (c) 2002



*

Company:



* @author unascribed

* @version 1.0

*/



public class Frame2 extends Frame {

JPanel jPanel1 = new JPanel();

JPanel jPanel2 = new JPanel();

JButton loadButton = new JButton();

public static ScrollingImagePanel panel, panels;



JButton nextButton = new JButton();

public String filename= "144.tif";

public File file;

public SeekableStream s;

public ImageDecoder dec;

protected int imageWidth, imageHeight;

public int nextpage = 1;

public RenderedOp image2 = null;

public RenderedImage op = null;



//Frame Constructor

public Frame2() {

try {

jbInit();



}

catch(IOException e) {

e.printStackTrace();

}

}



private void jbInit() throws IOException {

this.setLayout(null);

this.addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(WindowEvent e) {

this_windowClosing(e);

}

});



jPanel1.setBackground(Color.white);

jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));

jPanel1.setBounds(new Rectangle(1, 7, 816, 648));

jPanel1.setLayout(null);

jPanel2.setBackground(Color.lightGray);

jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));

jPanel2.setBounds(new Rectangle(1, 657, 816, 42));

loadButton.setText("Load");

loadButton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

try{

loadButton_actionPerformed(e);

}

catch(IOException IOE){

System.out.println(IOE);

}



}

});

nextButton.setText("Next");

nextButton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

nextButton_actionPerformed(e);

}

catch(IOException IOE){

System.out.println(IOE);

}



}

});

this.setResizable(false);

this.add(jPanel1, null);

this.add(jPanel2, null);

jPanel2.add(loadButton, null);

jPanel2.add(nextButton, null);



}



void this_windowClosing(WindowEvent e) {

System.exit(0);

}



//Load Image Button



void loadButton_actionPerformed(ActionEvent e) throws IOException {



file = new File(filename);

s = new FileSeekableStream(file);

dec = ImageCodec.createImageDecoder("tiff", s, null);



RenderedImage op =

new NullOpImage(dec.decodeAsRenderedImage(),

null,

OpImage.OP_IO_BOUND,

null);



Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);

ParameterBlock params = new ParameterBlock();



params.addSource(op);

params.add(0.55F); // x scale factor

params.add(0.335F); // y scale factor

params.add(0.00F); // x translate

params.add(0.00F); // y translate

params.add(interp); // interpolation method



image2 = JAI.create("scale", params);

int width = (int)(image2.getWidth() * .73);

int height = (int)(image2.getHeight() * .73);



panel = new ScrollingImagePanel(image2, 819, 648);



jPanel1.add(panel);

this.setVisible(true);



}





//Next Image Button



void nextButton_actionPerformed(ActionEvent e) throws IOException {





TIFFDecodeParam param = null;



file = new File(filename);

s = new FileSeekableStream(file);

dec = ImageCodec.createImageDecoder("tiff", s, param);





nextpage++;

System.out.println(nextpage);

RenderedImage op1 =

new NullOpImage(dec.decodeAsRenderedImage(nextpage),

null,

OpImage.OP_IO_BOUND,

null);



Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);

ParameterBlock params = new ParameterBlock();



params.addSource(op1);

params.add(0.55F); // x scale factor

params.add(0.335F); // y scale factor

params.add(0.00F); // x translate

params.add(0.00F); // y translate

params.add(interp); // interpolation method



image2 = JAI.create("scale", params);

int width = (int)(image2.getWidth() * .73); //1.03);

int height = (int)(image2.getHeight() * .73); //1.03);

panels = new ScrollingImagePanel(image2, width, height);



System.out.println(op1.getHeight());

jPanel1.add(panels);

this.setVisible(true);









}



}







You can e-mail me at SaumilTPatel@hotmail.com



Thanks in Advance



Saumil


   <<Less
About | Sitemap | Contact