资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
下边这个程序 是没有 Jrame 框架的,也就是不是 swing 界面开发的, 是程序在 没有人察觉的情况下拍照的, 每 77 毫秒拍一张图片, 图片命名为:当前时间 的 Long 毫秒,源码就在下边 自己慢慢看吧!public class PhotoGraph extends Threadprivate CaptureDeviceInfo captureDeviceInfo = null;private MediaLocator mediaLocator = null;private static Player player = null;private Buffer buffer = null;private BufferToImage bufferToImage = null;public Image img;public Image img2;public PhotoGraph() captureDeviceInfo = CaptureDeviceManager.getDevice(“vfw:Microsoft WDM Image Capture (Win32):0“); / 这里 放置的是视频驱动mediaLocator = new MediaLocator(“vfw:/0“); / 这里是视频地址DataSource ds = new DataSource();ds.setLocator(mediaLocator);try player = Manager.createRealizedPlayer(mediaLocator);player.start(); catch (NoPlayerException e)e.printStackTrace(); catch (CannotRealizeException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();public void run()try Thread.sleep(3000); catch (InterruptedException e) e.printStackTrace();System.out.println(“开始拍照.“);Date date = new Date();Long dateTime = date.getTime();while(true)FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl(“javax.media.control.FrameGrabbingControl“);buffer = fgc.grabFrame();bufferToImage = new BufferToImage(VideoFormat) buffer.getFormat();img2 = bufferToImage.createImage(buffer);FrameGrabbingControl fgcs =(FrameGrabbingControl) player.getControl(“javax.media.control.FrameGrabbingControl“);Buffer buf = fgcs.grabFrame(); / 获取当前祯并存入 Buffer 类BufferToImage btoi = new BufferToImage(VideoFormat) buf.getFormat();img2 = btoi.createImage(buf); / show the image this.setImg(img2);saveImage(img, “G:/photo_test/“+dateTime+“.jpg“);try Thread.sleep(77);dateTime+=77; catch (Exception e1) e1.printStackTrace();/* 储存图片* param image* param path*/public static void saveImage(Image image, String path) / 下边是 图片的大小BufferedImage bi = new BufferedImage(150, 150, BufferedImage.TYPE_INT_RGB);Graphics2D g2 = bi.createGraphics();/下边是图片在画布上的显示 位置 以及 大小g2.drawImage(image, 0, 0, 150, 150, null);/ 截取图片 / g2.drawRect(100, 100, 200, 200);FileOutputStream fos = null;try fos = new FileOutputStream(path); catch (FileNotFoundException e) e.printStackTrace();JPEGImageEncoder je = JPEGCodec.createJPEGEncoder(fos);JPEGEncodeParam jp = je.getDefaultJPEGEncodeParam(bi);jp.setQuality(0.4f, false);je.setJPEGEncodeParam(jp);try je.encode(bi);fos.close(); catch (ImageFormatException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();public synchronized Image getImg() return img;public synchronized void setImg(Image img) this.img = img;public static void main(String args) new PhotoGraph().start();
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号