The Artima Developer Community
Sponsored Link

Java Answers Forum
DisplayJAI detecting Exceptions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Sanjay Perera

Posts: 42
Nickname: angel6
Registered: Apr, 2004

DisplayJAI detecting Exceptions Posted: Oct 10, 2005 7:46 AM
Reply to this message Reply
Advertisement
Following is just a simple program using DisplayJAI to view image formats... and I select a text file with this program.

Question ID A
-------------
How to check whether the image1 was created successfully. Text files aren't image files.

Question ID B
-------------
Same as above question.

Question ID C
-------------
This is the biggest problem. When I selected the text file, the command prompt started to show the stacktrace which I believe i didn't check the exceptional case somewhere. Can someone give me an answer on how to detect such errors and stop printing stack trace in my command prompt. I use JDK 1.4 and JAI 1.1.2 or something. Please help!


import javax.media.jai.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.image.renderable.ParameterBlock;
import java.io.IOException;
import java.io.File;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.widget.*;
import java.beans.*;
import javax.swing.*;

public class Tempo extends DisplayJAI {

private PlanarImage source;
private Dimension dimension;
private static int paneWidth, paneHeight;

public Tempo() {
super();
}

public void loading(){
loadImage(new File("a.jpg"));
}

public void loadImage(File file){
if ( file.exists() && file.canRead() ) {
FileSeekableStream fileSeekableStream =null;
try {
fileSeekableStream = new FileSeekableStream(file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
RenderedOp image1=null ;

// Question ID A - Start
image1 = JAI.create("stream", fileSeekableStream);
// Question ID A - End

ParameterBlock params = new ParameterBlock();
params.addSource(image1);
params.add(0.5F); // x scale factor
params.add(0.5F); // y scale factor
params.add(0.0F); // x translate
params.add(0.0F); // y translate
Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_NEAREST);

// Question ID B - Start
source = JAI.create("scale", params);
// Question ID B - End

// Question ID C - Start
set((RenderedImage) source,0,0);
// Question ID C - End
}
}

public void paintComponent(Graphics g){
super.paintComponent(g);
}

public static void main (String args[]){
JFrame jf = new JFrame("Sample");
Tempo tmp = new Tempo();
tmp.loading();
jf.getContentPane().add(tmp);
jf.setSize(200,200);
jf.setVisible(true);
}

public Dimension getPreferredSize(){
return new Dimension(200,200);
}
}

Topic: Logging in JSP Previous Topic   Next Topic Topic: Binding a Vector index to an Item Listener

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use