OSDN Git Service

[更新]NyARToolkit
[nyartoolkit-and/nyartoolkit-and.git] / sample / qt / jp / nyatla / nyartoolkit / qt / sample / QtCaptureTest.java
1 /* 
2  * PROJECT: NyARToolkit QuickTime sample program.
3  * --------------------------------------------------------------------------------
4  * The MIT License
5  * Copyright (c) 2008 nyatla
6  * airmail(at)ebony.plala.or.jp
7  * http://nyatla.jp/nyartoolkit/
8  * 
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  * 
26  */
27 package jp.nyatla.nyartoolkit.qt.sample;
28
29 import jp.nyatla.nyartoolkit.NyARException;
30 import jp.nyatla.nyartoolkit.qt.utils.*;
31
32 import java.awt.*;
33 /**
34  * QuickTimeキャプチャプログラム
35  *
36  */
37 public class QtCaptureTest extends Frame implements QtCaptureListener
38 {
39         private static final long serialVersionUID = -734697739607654631L;
40
41         public QtCaptureTest() throws NyARException
42         {
43                 setTitle("QtCaptureTest");
44                 setBounds(0, 0, 320 + 64, 240 + 64);
45                 capture = new QtCameraCapture(320, 240, 30f);
46                 capture.setCaptureListener(this);
47                 //キャプチャイメージ用のラスタを準備
48                 raster = new QtNyARRaster_RGB(320, 240);
49         }
50
51         private QtCameraCapture capture;
52
53         private QtNyARRaster_RGB raster;
54
55         public void onUpdateBuffer(byte[] pixels)
56         {
57                 raster.setBuffer(pixels);
58                 Image img = raster.createImage();
59                 Graphics g = getGraphics();
60                 g.drawImage(img, 32, 32, this);
61         }
62
63         private void startCapture()
64         {
65                 try {
66                         capture.start();
67                 } catch (Exception e) {
68                         e.printStackTrace();
69                 }
70         }
71
72         public static void main(String[] args)
73         {
74                 try {
75                         QtCaptureTest mainwin = new QtCaptureTest();
76                         mainwin.setVisible(true);
77                         mainwin.startCapture();
78                 } catch (Exception e) {
79                         e.printStackTrace();
80                 }
81
82         }
83
84 }