1 Reply Latest reply: May 5, 2014 2:52 PM by rp0428 RSS

    Reading dicim image from another directory

    3840add5-e165-472e-ad5c-00fdc7d47bba

      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 {

        public static void 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 = new JPanel() {

        public void 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();

          }

        }

      }

        • 1. Re: Reading dicim image from another directory
          rp0428
          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 frameThe 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

          The code you posted does NOT match the description you gave.

           

          That code doesn't open a dialog box. It opens the file whose name is given as a command line argument.

           

          You haven't shown us what command line argument you are using or what result you get.

           

          Post a copy of the exact session showing how that code is called and the results that it produces.