Hi
I am trying to crate an interface for the following file (code). The interface that I am trying to create will display a open dialog box where the user chooses which image (.dcm) it would like to open and then it should open it in a frame. The code below shows opening the image. The image opens when the image is in the same folder as the source code but I need it to open from a given path and I am really confused on how to do that. I have tried a lot of methods but still doesn't seem work. Are there any suggestions on how to make it work. Any ideas will be appreciated.
This is the code (assuming the parameter that you are passing in image.dcm, I have tried a full path name on mac computer which is like /Users/Documents/image.dcm, where this path name never works):
/**
* This class displays the first frame of a file from any format
* supported by ImageIO.
* In the case of DICOM files, stored values are displayed as
* is, without using Value of Interest or Presentation LUTs.
*/
class Read1 {
publicstaticvoid main(String[] s) {
try {
System.out.println(s);
if (s.length != 1) {
System.err.println("Please supply an input file");
System.exit(1);
}
ImageIO.scanForPlugins();
final BufferedImage bi = ImageIO.read(new File(s[0]));
if (bi == null) {
System.err.println("read error");
System.exit(1);
}
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Rectangle bounds = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
JPanel panel = newJPanel() {
publicvoid paintComponent(Graphics g) {
Rectangle r = g.getClipBounds();
((Graphics2D)g).fill(r);
if (bounds.intersects(r))
g.drawImage(bi, 0, 0, null);
}
};
jf.getContentPane().add(panel);
panel.setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
jf.pack();
jf.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}