2 * Copyright 2007 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.j2me;
19 import com.google.zxing.MonochromeBitmapSource;
20 import com.google.zxing.Reader;
21 import com.google.zxing.MultiFormatReader;
22 import com.google.zxing.Result;
23 import com.google.zxing.ReaderException;
25 import javax.microedition.lcdui.Image;
26 import javax.microedition.media.MediaException;
29 * @author Sean Owen (srowen@google.com)
31 final class SnapshotThread extends Thread {
33 private static SnapshotThread currentThread;
35 private final ZXingMIDlet zXingMIDlet;
37 SnapshotThread(ZXingMIDlet zXingMIDlet) {
38 this.zXingMIDlet = zXingMIDlet;
41 static synchronized void startThread(ZXingMIDlet zXingMIDlet) {
42 if (currentThread == null) {
43 currentThread = new SnapshotThread(zXingMIDlet);
44 currentThread.start();
50 zXingMIDlet.getPlayer().stop();
51 byte[] snapshot = zXingMIDlet.getVideoControl().getSnapshot(null);
52 Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
53 MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage);
54 Reader reader = new MultiFormatReader();
55 Result result = reader.decode(source);
56 zXingMIDlet.handleDecodedText(result.getText());
57 } catch (ReaderException re) {
58 zXingMIDlet.showError(re);
59 } catch (MediaException me) {
60 zXingMIDlet.showError(me);
61 } catch (Throwable t) {
62 zXingMIDlet.showError(t);
65 zXingMIDlet.getPlayer().start();
66 } catch (MediaException me) {
68 zXingMIDlet.showError(me);