OSDN Git Service

Merge branch 'git-svn'
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.1.0 / 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         public JmfCaptureTest() throws NyARException
44         {
45                 setTitle("JmfCaptureTest");
46                 setBounds(0, 0, 320 + 64, 240 + 64);
47                 capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
48                 capture.setCaptureListener(this);
49         }
50
51         private JmfCameraCapture capture;
52
53         public void onUpdateBuffer(Buffer i_buffer)
54         {
55                 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
56                 Image img = b2i.createImage(i_buffer);
57                 Graphics g = getGraphics();
58                 g.drawImage(img, 32, 32, this);
59         }
60
61         private void startCapture()
62         {
63                 try {
64                         capture.start();
65                 } catch (Exception e) {
66                         e.printStackTrace();
67                 }
68         }
69
70         public static void main(String[] args)
71         {
72                 try {
73                         JmfCaptureTest mainwin = new JmfCaptureTest();
74                         mainwin.setVisible(true);
75                         mainwin.startCapture();
76                 } catch (Exception e) {
77                         e.printStackTrace();
78                 }
79
80         }
81
82 }