jmf 拍照, 怎么样设置保存的图片大小?

上传人:正** 文档编号:35737740 上传时间:2018-03-19 格式:DOC 页数:3 大小:29KB
返回 下载 相关 举报
jmf 拍照, 怎么样设置保存的图片大小?_第1页
第1页 / 共3页
jmf 拍照, 怎么样设置保存的图片大小?_第2页
第2页 / 共3页
jmf 拍照, 怎么样设置保存的图片大小?_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《jmf 拍照, 怎么样设置保存的图片大小?》由会员分享,可在线阅读,更多相关《jmf 拍照, 怎么样设置保存的图片大小?(3页珍藏版)》请在金锄头文库上搜索。

1、下边这个程序 是没有 Jrame 框架的,也就是不是 swing 界面开发的, 是程序在 没有人察觉的情况下拍照的, 每 77 毫秒拍一张图片, 图片命名为:当前时间 的 Long 毫秒,源码就在下边 自己慢慢看吧!public class PhotoGraph extends Threadprivate CaptureDeviceInfo captureDeviceInfo = null;private MediaLocator mediaLocator = null;private static Player player = null;private Buffer buffer = nu

2、ll;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.s

3、etLocator(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 (InterruptedE

4、xception 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(Vide

5、oFormat) 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();i

6、mg2 = 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) / 下边是 图片的大小BufferedIm

7、age 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

8、 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();

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号