Pow veio naum sei se isso pode te ajudar eu estou uzando swing mas pode extends applet
blic class Fotografia extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
public static Player player = null;
public CaptureDeviceInfo di = null; // @jve:decl-index=0:
public MediaLocator ml = null; // @jve:decl-index=0:
public JButton capture = null;
public Buffer buf = null;
public Image img = null;
public VideoFormat vf = null;
public BufferToImage btoi = null;
public ImagePanel imgpanel = null;
private JButton captura = null;
private ClienteDB cliDB = null;
private String pathFotos = "";
public int clienteID = 0;
/** Creates new form Foto */
public Fotografia(ClienteDB DB, int cliID, String path) {
super();
this.cliDB = DB;
this.clienteID = cliID;
this.pathFotos = path;
initComponents();
initialize();
//setLocation(170, 05);
setLocation(300, 300);
getContentPane().add(captura);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
if (player != null) {
player.close();
}
player.deallocate();
}
});
}
private void initialize() {
this.setLayout(new BorderLayout());
// this.setSize(300, 290);
this.setSize(300, 300);
this.setMaximumSize(new Dimension(largura, altura));
this.setMinimumSize(new Dimension(largura, altura));
this.add(getCaptura(), BorderLayout.SOUTH);
this.setVisible(true);
//String str2 = "vfw://0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32) : 0";
di = CaptureDeviceManager.getDevice(str2);
ml = new MediaLocator("vfw://0");
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if ((comp = player.getVisualComponent()) != null) {
add(comp, BorderLayout.NORTH);
}
add(captura, BorderLayout.SOUTH);
} catch (Exception e) {
e.printStackTrace();
}
}
private JButton getCaptura() {
if (captura == null) {
captura = new JButton(" -- Capturar imagem -- ");
captura.setBounds(new Rectangle(10, 10, 10, 10)); //Corresponde a posição(x=50 e y=50) e Largura(width=50) e Altura(height=50)
captura.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
buf = fgc.grabFrame();
btoi = new BufferToImage((VideoFormat) buf.getFormat());
img = btoi.createImage(buf);
try {
gravaImg();
player.stop();
player.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
return captura;
}
//public void gravaImg(Image imagem) throws IOException {
public void gravaImg() throws IOException {
String caminho = "";
String nmArquivo = String.valueOf(clienteID) + ".jpg";
try {
caminho += this.pathFotos + nmArquivo;
ImageIO.write((RenderedImage) img, "jpg", new File(caminho));
JOptionPane.showMessageDialog(this, "Informações e imagem registradas com sucesso.");
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Não foi possível localizar o dispositivo para a captura da imagem.");
e.printStackTrace();
}
try {
img = new ImageIcon(caminho).getImage();
} catch (RuntimeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
ImageUtils.saveCompressedImage(ImageUtils.resizeImage(img, ImageUtils.IMAGE_JPEG, 100, 300), caminho, ImageUtils.IMAGE_JPEG);
int teste = ImageUtils.IMAGE_JPEG;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
player.close();
this.dispose();
}
class ImagePanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
public Image myimg = null;
public ImagePanel() {
JOptionPane.showMessageDialog(null, "Setando a classe...");
setLayout(null);
setSize(largura, altura);
setMinimumSize(new Dimension(largura, altura));
setMaximumSize(new Dimension(largura, altura));
}
public void setImage(Image img) {
this.myimg = img;
repaint();
}
@Override
public void paint(Graphics g) {
if (myimg != null) {
g.drawImage(myimg, 0, 0, this);
}
}
}
public int retornarFotoID() {
return clienteID;
}
Pessoal, não to conseguindo colocar pra rodar o código acima.
Dá os seguintes erros:
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
Access restriction: The type CaptureDeviceInfo is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type Manager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type MediaLocator is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type Player is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type CaptureDeviceManager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type FrameGrabbingControl is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type VideoFormat is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type BufferToImage is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type Player is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type CaptureDeviceInfo is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type MediaLocator is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type Buffer is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type VideoFormat is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type BufferToImage is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type CaptureDeviceManager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method getDevice(String) from the type CaptureDeviceManager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The constructor MediaLocator(String) is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type MediaLocator is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type Manager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method createRealizedPlayer(MediaLocator) from the type Manager is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method start() from the type Player is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method getVisualComponent() from the type Player is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type FrameGrabbingControl is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type FrameGrabbingControl is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method getControl(String) from the type Controller is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method grabFrame() from the type FrameGrabbingControl is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The constructor BufferToImage(VideoFormat) is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type BufferToImage is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The type VideoFormat is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method getFormat() from the type Buffer is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
Access restriction: The method createImage(Buffer) from the type BufferToImage is not accessible due to restriction on required library D:\Arquivos de programas\Java\jre6\lib\ext\jmf.jar
at CapturaFoto.<init>(CapturaFoto.java:12)
at Foto.getCapturaFoto1(Foto.java:61)
at Foto.<init>(Foto.java:44)
at Foto.main(Foto.java:70)
Utilizar jmf não é uma opção adequada. Jmf foi descontinuada a zilhões de anos atras. A única opção é fazer jni com directshow.
http://www.humatic.de/htools/dsj.htm
Ola boa terde pessoal.
Então com base no post eu criei uma outro form só para a captura da imagem mais quando eu gero o jar o mesmo não executa, alguém pode dar uma luz de como eu faço para gerar o jar.Para que eu possa ter uma noção de onde estou errando.Valeu…
Eu preciso fazer em vez de gravar uma imagem, gravar um vídeo. Alguém ja conseguiu fazer isso?
Utiliza a JMF.jar do diretório do JMF instalado.
Isto resolveu o meu problema.
amigos estou tentando fazer essa captura d imagem agora, mas coloquei o codigo mas ele nao reconhe o medialocator e nem CaptureDeviceInfo,e nem Manager.createDataSource podem me ajudar?
valeu
ola jrfercar pode me ajudar com o JMF…estou aprendendo a capturar imagem agora…
valeu
Cara está dando um erro de compilação que diz que a Classe Banco não existe, que classe é essa?
amigos
estou precisando desenvolver esta aplicação
um cadastro de acesso com foto
preciso dar um import em algum .jar ?
Psvtec
voce configurou a maquina ou o pc pra quando tirar a foto salvar na pasta
como configurou ?
e o nome do arquivo ?
String caminho = "C:\\Documents and Settings\\Patrick\\Desktop" +
"\\PontoEletronico\\Fotos\\"+"00"+(Integer.parseInt(Banco.
retornaGeral("select max(ID) from Funcionarios").toString())+1)+".JPG";
funciona apenas com webcam ?
e camera digital ?
olá pessoal
consegui montar um cadastro com foto
mas a questão, o cara clica na web cam pra tirar a foto, dae tem que salvar em um local
e no java chamar essa figura que ele salvou
tem como ser + automatico isso :?
obrigado
Psvtec sera que vc pode me ajudar, estou tentando executar essa classe porem nao entendo porque ele da esse erro!
javax.media.NoPlayerException: Cannot find a Player for :vfw://0
at javax.media.Manager.createPlayerForContent(Manager.java:1412)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createRealizedPlayer(Manager.java:553)
at packageWebCapture.CapturaFoto.initialize(CapturaFoto.java:61)
at packageWebCapture.CapturaFoto.(CapturaFoto.java:46)
at packageWebCapture.TesteCap.main(TesteCap.java:11)
Boa tarde, pessoal alguem poderia me ajudar com o seguinte problema,
Estou utilizando JMF para capturar imagens, mas gostaria de saber se tem como selecionar a câmera antes de começar a Captura,
pois quando inicializo o sistema ele pega a câmera padrão do notebook.
Gostaria de por exemplo, ter 3 câmeras conectadas mas quando eu iniciar a aplicação escolher qual irei utilizar…
Segue abaixo o código que inicializa a WebCam
public boolean ligaDesligaWebCam() throws
IOException, NoPlayerException, CannotRealizeException {
if (status == true) {
JOptionPane.showMessageDialog(null, "A camera já está ligada");
} else if(status == false) {
player = Manager.createRealizedPlayer(new MediaLocator("vfw://0"));
//player.getControlPanelComponent().setSize(300, 280);
player.getVisualComponent().setSize(300, 280);
player.start();
jPanelWebCamVideo.add(player.getVisualComponent());
status = true;
}
return status;
}