The following ideas are implemented:
1. Set the camera background, such as the use of red cloth or blue, etc., white walls can also.
2. Select HD camera, such as Logitech and other high-definition cameras, the higher the resolution, the better.
3. Use Imagecaponweb to process the photo.
4. Call the control's Start method to get the webcam video
5. Call the CAP () method to take a picture
6. Call the Selectrect method to select the Avatar area, not satisfied with the words can be manually fine-tuned.
7. Call the Cutselected method crop using the selected area
8. Save the photo results.
The code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<%@ page contenttype= "text/html; Charset=utf-8 "language=" java "import=" java.sql.*,java.io.* "errorpage=" "%><%string savePath= Config.getservletcontext (). Getrealpath ("/") + "//"; File Tmp_path=new file (Savepath); Tmp_path.mkdirs (); System.out.println ("Photo Data save path:" +savepath); String pic_base_64_data=request.getparameter ("Picdata"), or//if the following code output True indicates the need to adjust the server software operating parameters to address the size limit of the accept post data, for example// Tomcat would need to configure maxpostsize= "0" in server.xml to unblock the upload data size limit <connector port= "8080" protocol= "http/1.1"//Conne ctiontimeout= "20000"//redirectport= "8443" maxpostsize= "0"/>//System.out.println (null==pic_base_64_data ); System.out.println ("Base64 string length:" +pic_base_64_data.length ()); String fileformat=request.getparameter ("Picext"); Sun.misc.BASE64Decoder decode=new Sun.misc.BASE64Decoder (); byte[ ] Datas=decode.decodebuffer (Pic_base_64_data); String filename=string.valueof (System.currenttimemillis ()) +fileformat; File File=new file (savepath+filename); OutputStream fos=new FILEOUTPUTStream (file); System.out.println ("Picture file name:" +filename); Fos.write (datas); Fos.close (); Out.print ("<a href=" + Request.getcontextpath () + "/" + filename + "' >click here</a>"); Out.flush (); Out.close ();%>