/*
- * Copyright 2008 Google Inc.
+ * Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package com.google.zxing.client.j2se;
-import com.google.zxing.MonochromeBitmapSource;
+import com.google.zxing.BinaryBitmap;
+import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
+import com.google.zxing.common.HybridBinarizer;
-import javax.imageio.ImageIO;
-import javax.swing.ImageIcon;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JTextArea;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.IOException;
import java.net.MalformedURLException;
+import javax.imageio.ImageIO;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+
/**
* <p>Simple GUI frontend to the library. Right now, only decodes a local file.
* This definitely needs some improvement. Just throwing something down to start.</p>
*
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
*/
public final class GUIRunner extends JFrame {
panel.add(textArea);
setTitle("ZXing");
setSize(400, 400);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
setContentPane(panel);
setLocationRelativeTo(null);
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws MalformedURLException {
GUIRunner runner = new GUIRunner();
runner.setVisible(true);
runner.chooseImage();
}
- private void chooseImage() {
+ private void chooseImage() throws MalformedURLException {
JFileChooser fileChooser = new JFileChooser();
- fileChooser.showOpenDialog(GUIRunner.this);
+ fileChooser.showOpenDialog(this);
File file = fileChooser.getSelectedFile();
- ImageIcon imageIcon;
- try {
- imageIcon = new ImageIcon(file.toURI().toURL());
- } catch (MalformedURLException mue) {
- throw new RuntimeException(mue);
- }
+ Icon imageIcon = new ImageIcon(file.toURI().toURL());
setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight() + 100);
imageLabel.setIcon(imageIcon);
String decodeText = getDecodeText(file);
if (image == null) {
return "Could not decode image";
}
- MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
+ LuminanceSource source = new BufferedImageLuminanceSource(image);
+ BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
try {
- result = new MultiFormatReader().decode(source);
+ result = new MultiFormatReader().decode(bitmap);
} catch (ReaderException re) {
return re.toString();
}
return result.getText();
}
-}
\ No newline at end of file
+}