我正在开发一个java程序,以便在注册时使用网络摄像头捕获员工图像.我可以毫无问题地获得图片,并将其保存在我的C:驱动器中,但在检索图像时,只有部分图像显示在标签上.有没有办法在保存之前重新调整JPEG大小?还是在显示之前?喜欢缩小它没有质量损失....
非常感谢Cheerz!:)!
好的伙计们......这里有: - 我已经按照我使用它们的方式对代码进行了评论.
//This method will capture the image from the interface and save it under the unique employee ID
public String captureImage(int picId){
FrameGrabbingControl ControlFG = (FrameGrabbingControl)
broadcast.getControl("javax.media.control.FrameGrabbingControl");
Buffer buffer = ControlFG.grabFrame();
BufferToImage image = new BufferToImage((VideoFormat)buffer.getFormat());
img = image.createImage(buffer);
path="c:\\employee"+picId+".jpg";
saveJPG(img,path);//method will save the image
return path;
}
public void saveJPG(Image img, String s){***//method will save the image***
System.out.println(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{ …Run Code Online (Sandbox Code Playgroud)