12.07.2015 Views

Digital Image Processing (using Java)

Digital Image Processing (using Java)

Digital Image Processing (using Java)

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}error("No histogram data to save!");return;}else {fileChooser.setDialogTitle("Save histogram");if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {try {File file = fileChooser.getSelectedFile();if (file.exists()) {int response = JOptionPane.showConfirmDialog(this,"File will be overwritten! Are you sure?", "File exists",JOptionPane.OK_CANCEL_OPTION);if (response != JOptionPane.OK_OPTION)return;}histogram.write(new FileWriter(file));fileChooser.rescanCurrentDirectory();}catch (IOException e) {error("Cannot open output file.");}}}// Displays an error message in a dialog boxpublic void error(String message) {JOptionPane.showMessageDialog(this, message, "Error",JOptionPane.ERROR_MESSAGE);}public static void main(String[] argv) {if (argv.length > 0) {try {<strong>Image</strong>Decoder input = <strong>Image</strong>File.create<strong>Image</strong>Decoder(argv[0]);Buffered<strong>Image</strong> image = input.decodeAsBuffered<strong>Image</strong>();Histogram hist = new Histogram(image);HistogramTool histTool = new HistogramTool(hist, argv[0]);- 32 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!