JMF Java use in the preparation of camera photographed procedures (1)
I divided into two procedures, interesting and boring, recently made several interesting projects, one of them, even the camera should take pictures of the proceedings. For the camera at the scene, generating photo, the main use Java Media Framework (JMF).
SUN first to download the latest JMF, and then installed. Http://java.sun.com/products/java-media/jmf/index.jsp
Then, talk about demand
1. Photographed by camera
2. In the text box enter the file name
3. Press the camera button, access to the camera images
4. In the photograph taken Gongkuang interception of a fixed size photographs.
5. For the preservation of local images jpg format, not quality compression
The key technology, we also believe that the most interesting part is how to get a camera, and took a photograph of.
JMF use of the code is simple:
/ / Use of these three categories were driven camera access, and access to the camera image flow, access to the image flow is a Swing component of the Component
Public static Player player = null;
Private CaptureDeviceInfo di = null;
Private MediaLocator ml = null;
/ / Documentation provided in the drive way, why write so I do not know:)
String str1 = "vfw: Logitech USB Video Camera: 0";
String str2 = "vfw: Microsoft WDM Image Capture (Win32): 0";
Di = CaptureDeviceManager.getDevice (str2);
Ml = di.getLocator ();
Try
(
Player = Manager.createRealizedPlayer (ml);
Player.start ();
Component comp;
If ((comp = player.getVisualComponent ())! = Null)
(
Add (comp, BorderLayout.NORTH);
)
)
Catch (Exception e)
(
E.printStackTrace ();
)
The next step was to click on camera, access to the camera's current image.
Code is very simple:
Private JButton capture;
Private Buffer buf = null;
Private BufferToImage btoi = null;
Private ImagePanel imgpanel = null;
Private Image img = null;
Private ImagePanel imgpanel = null;
JComponent c = (JComponent) e.getSource ();
If (c == capture) / / If you press the button to take pictures
(
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl ( "javax.media.control.FrameGrabbingControl");
Buf = fgc.grabFrame (); / / Zhen access to current and deposit category btoi Buffer = new BufferToImage ((VideoFormat) buf.getFormat ());
Img = btoi.createImage (buf); / / show the image
Imgpanel.setImage (img);
)
Save images are not to say, for example the following code
Tags: Java procedures, jmf






