Webカメラを使用して登録時に従業員の画像をキャプチャする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{
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");
}
}
保存中に画像を拡大縮小できるので、拡大縮小された画像を取得できます..