OSDN Git Service

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