Salamlar.Asagadaki kodla Javada webcamera ile cekdiyim sekli nasil  MySQL bazaya
yazdira bilirim?

package az;

import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class BasicWebCam extends JFrame implements ActionListener {

private JPanel contentPane;
private JPanel pnlCam = new JPanel();
public CaptureDeviceInfo captureDeviceInfo;
public MediaLocator mediaLocator;
public Player player;
private Component comp;
public javax.swing.Timer timer = new javax.swing.Timer(250, (ActionListener) this);
public Buffer BUF;
public Image img;
public BufferToImage BtoI;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BasicWebCam frame = new BasicWebCam();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public BasicWebCam() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 353, 327);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

pnlCam.setBounds(10, 11, 320, 240);
contentPane.add(pnlCam);
JButton btnCapture = new JButton("Sekil cek");
btnCapture.setVisible(true);
btnCapture.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
actionCapture();
}
});
btnCapture.setBounds(124, 262, 89, 23);
contentPane.add(btnCapture);

init();
}

public void init() {
String strDevice = "vfw:Microsoft WDM Image Capture (Win32):0";
mediaLocator = new MediaLocator("vfw://0");
// FOR LINUX
// String strDevice = "v4l:Laptop Integrated Webcam:0";
// mediaLocator = new MediaLocator("v4l://0");
captureDeviceInfo = CaptureDeviceManager.getDevice(strDevice);
showVid();
}

private void showVid() {
try {
player = Manager.createRealizedPlayer(mediaLocator);
player.start();
if ((comp = player.getVisualComponent()) != null) {
comp.setSize(pnlCam.getWidth(), pnlCam.getHeight());
// comp.setPreferredSize(new Dimension(pnlCapture.getWidth(),
// pnlCapture.getHeight()));
pnlCam.add(comp);
}
Thread.sleep(1000);
timer.start(); // start timer
} catch (Exception e) {
e.printStackTrace();
}
}

public void actionCapture() {
// Grab a frame
// comp.setSize(pnlCapture.getWidth(), pnlCapture.getHeight());
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
BUF = fgc.grabFrame();

// Convert it to an image
BtoI = new BufferToImage((VideoFormat) BUF.getFormat());
img = BtoI.createImage(BUF);

// resize
img = resizeImage(img, pnlCam.getWidth(), pnlCam.getHeight());

// show the image
// pnlImage.setImage(img);
img.getGraphics().drawString(getDateTime("yyyy/MM/dd HH:mm:ss") + " - ColinCoderator", 50, 235);

// save image
String fileName = getDateTime("yyyy-MM-dd_HH-mm-ss") + ".jpg";
String path = "C:/Users/MEHMAN/Desktop/" + fileName;
System.out.println(path);
// save image
saveJPG(img, path);
}

public static 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 io) {
System.out.println("File Not Found");
}

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 (java.io.IOException io) {
System.out.println("IOException");
}
}

public Image resizeImage(Image img, int width, int height) {
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(img, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}

public static String getDateTime(String format) {
DateFormat dateFormat = new SimpleDateFormat(format);
Calendar cal = Calendar.getInstance();
return (dateFormat.format(cal.getTime()));
}

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub

}
}

soruldu: 09 Eyl '12, 13:35

mehmanbashirov's gravatar image

mehmanbashirov
211253138
cevap kabul oranı: 16%

değiştirildi: 09 Eyl '12, 17:36

rahmanyazgan's gravatar image

rahmanyazgan ♦
4.4k83559


Aslinda Web kamera ile resim cekmek ve Database bu resmi yazmak ayri seyler bunu bir butun gibi dusunemeyiz. Web Kamerada resim cekildikten sonra bu resim herhangi bir directory-e kaydedilir bunu Database blob yipinde yazabilirsiniz.

permanent link

cevaplandı: 12 Eyl '12, 05:07

selcukoglu's gravatar image

selcukoglu
647111629
cevap kabul oranı: 16%

Çektiğiniz görüntüyü binary'e çevirip ardından Blob Type daki bir kolona yazdırarak kolayca kaydedebilirsiniz. http://www.java2s.com/Code/Java/Database-SQL-JDBC/InsertpicturetoMySQL.htm buradada örneği bulunmakta.

permanent link

cevaplandı: 09 Eyl '12, 19:06

Dreamcatcher's gravatar image

Dreamcatcher
2106812
cevap kabul oranı: 22%

Cevabınız
toggle preview

Bu soruyu takip et

E-Posta üzerinden:

Üyelik girişi yaptıktan sonra abonelik işlemlerini yapabilirsiniz

RSS üzerinden:

Cevaplar

Cevaplar ve Yorumlar

Yazı Formatlama

  • *italic* ya da _italic_
  • **bold** ya da __bold__
  • link:[text](http://url.com/ "başlık")
  • resim?![alt text](/path/img.jpg "başlık")
  • liste: 1. Foo 2. Bar
  • temel HTML etiketleri de kullanılabilir

Bu sorunun etiketleri:

×1,079

Soruldu: 09 Eyl '12, 13:35

Görüntüleme: 635 kez

Son güncelleme: 12 Eyl '12, 05:07

powered by BitNami OSQA