Sat Nov 10, 2012 10:48 am
Sat Nov 10, 2012 12:43 pm
Mon Nov 12, 2012 12:09 pm
Mon Nov 12, 2012 9:11 pm
public interface ClientConstant
{
public static final String SERVER_ADDRESS="127.0.0.1";
public static final int SERVER_PORT=4567;
public static final int CLIENT_NUMBER=100;
public static final String DISCONNECT_STRING="DISCONNECT";
public static final String MESSAGE_SEPARATOR=" >> ";
}
Mon Nov 12, 2012 11:24 pm
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-client-419417.html#7372-jmf-2.1.1e-oth-JPR
Mon Nov 19, 2012 6:45 am
Tue Nov 27, 2012 5:23 pm
Thu Nov 29, 2012 5:28 pm
Fri Nov 30, 2012 7:59 am
Sat Dec 01, 2012 12:10 am
try {
ds = javax.media.Manager.createDataSource(locator);
} catch (Exception e) {
e.printStackTrace();
return "Couldn't create DataSource";
}
Error : Couldn't create DataSource
javax.media.NoDataSourceException: Cannot find a DataSource for: vfw://0
at javax.media.Manager.createDataSource(Manager.java:1037)
at clientside.AVTransmit2.createProcessor(AVTransmit2.java:95)
at clientside.AVTransmit2.start(AVTransmit2.java:51)
at clientside.MessageRecever.run(MessageRecever.java:187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.util.Calendar;
import javax.media.Buffer;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.swing.JButton;
import javax.swing.JComponent;
public class Main extends Panel implements ActionListener{
public static Player player=null;
public CaptureDeviceInfo di=null;
public MediaLocator ml=null;
public JButton capture=null;
public Buffer buf=null;
public Image img=null;
public VideoFormat vf=null;
public BufferToImage btoi=null;
public ImagePanel imgpanel=null;
public int capturenumber=0;
public Main(){
setLayout(new BorderLayout());
setSize(320,550);
imgpanel=new ImagePanel();
capture= new JButton("Capture");
capture.addActionListener(this);
String str = "vfw:Microsoft WDM Image Capture (Win32):0";
di=CaptureDeviceManager.getDevice(null);
ml = new MediaLocator(str);
try{
player=Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if((comp = player.getVisualComponent())!=null){
add(comp,BorderLayout.NORTH);
}
add(capture,BorderLayout.CENTER);
add(imgpanel,BorderLayout.SOUTH);
}
catch(Exception ex){
ex.printStackTrace();
}
}
public static void main(String[] args){
Frame f=new Frame("Take picture");
Main cf = new Main();
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e){
playerclose();
System.exit(0);
}
});
f.add(cf);
f.pack();
f.setSize(320, 550);
f.setVisible(true);
}
public static void playerclose(){
player.close();
player.deallocate();
}
public void actionPerformed(ActionEvent e) {
JComponent c = (JComponent) e.getSource();
if(c==capture){
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
buf = fgc.grabFrame();
btoi= new BufferToImage((VideoFormat)buf.getFormat());
img = btoi.createImage(buf);
imgpanel.setImage(img);
Calendar cal= Calendar.getInstance();
@SuppressWarnings("static-access")
int data = (cal.getTime().getYear()+1900)*10000+ (cal.getTime().getMonth()+1)*100+cal.getTime().getDate();
saveJPG(img,"D:\\"+ data +capturenumber+".jpg");
capturenumber++;
}
}
private void saveJPG(Image img, String s) {
BufferedImage bi= new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics2D g2=bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out=null;
try{
out = new FileOutputStream(s);
}
catch(java.io.FileNotFoundException ex){
ex.printStackTrace();
}
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param= encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(0.5f, false);
encoder.setJPEGEncodeParam(param);
try{
encoder.encode(bi);
out.close();
}
catch(Exception ex){
ex.printStackTrace();
}
}
public class ImagePanel extends Panel{
public Image myimg=null;
public ImagePanel(){
setLayout(null);
setSize(320,240);
}
public void setImage(Image img){
this.myimg=img;
repaint();
}
@Override
public void paint(Graphics g){
if(myimg != null){
g.drawImage(myimg,0,0,this);
}
}
}
}
import java.awt.BorderLayout;
import java.util.Vector;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FormatControl;
import javax.swing.JFrame;
public class main {
CaptureDeviceInfo cam;
MediaLocator locator;
Player player;
FormatControl formatControl;
/**
* @param args
*/
public main(){
try{
// List out available Devices to Capture Video.
Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList ( null );
// Iterating list
for(CaptureDeviceInfo temp : list){
// Checking whether the current device supports VfW
// VfW = Video for Windows
if(temp.getName().startsWith("vfw:")){
System.out.println("Found : "+temp.getName().substring(4));
// Selecting the very first device that supports VfW
cam = temp;
System.out.println("Selected : "+cam.getName().substring(4));
break;
} else {
System.out.println(temp.getName().substring(4));
cam = temp;
}
}
if (cam != null){
System.out.println("Camera found.");
locator = cam.getLocator();
} else System.out.println("Camera not found.");
if(locator != null){
// Create a Player for Media Located by MediaLocator
player = Manager.createRealizedPlayer(locator);
if(player != null){
// Starting the player
player.start();
// Creating a Frame to display Video
JFrame f = new JFrame();
f.setTitle("Test Webcam");
f.setLayout(new BorderLayout());
// Adding the Visual Component to display Video captured by Player
// from URL provided by MediaLocator
f.add(player.getVisualComponent(), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new main();
}
}
Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList ( null );
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.