Java photo processing:
/*** @ Author YZH photo processing * @ return * @ throws exception */Public String getpersonnelphoto () throws exception {httpservletrequest Req = servletactioncontext. getrequest (); httpservletresponse response = servletactioncontext. getresponse (); PNO = (string) session. get ("no"); string zhigongbhstr = req. getparameter ("bh"); If (zhigongbhstr = NULL) zhigongbhstr = PNO; string xingbiestr = req. getparameter ("xingbie "); If (zhigongbhstr! = NULL & xingbiestr! = NULL) {quapersonphoto pH = personqualityservice. getquapersonphoto (zhigongbhstr); File URL = NULL; If (pH = NULL) {getdefaultpic (xingbiestr, URL, response);} else {If (pH. getphoto () = NULL) {getdefaultpic (xingbiestr, URL, response);} else {byte [] photobytes = Ph. getphoto (); response. setcontenttype ("image/JPEG"); outputstream toclient = response. getoutputstream (); inputstream in = new bytearrayinputst Ream (photobytes); int Len; byte [] Buf = new byte [1024]; while (LEN = in. Read (BUF, 0, 1024 ))! =-1) {toclient. write (BUF, 0, Len);} toclient. close ();/* // method 2 * image = NULL; * inputstream isphoto = new bytearrayinputstream (photobytes); * image = ImageIO. read (isphoto); * response. setcontenttype ("image/JPEG"); * specify imageencoder encoder = * specify codec. createjpegencoder (response. getoutputstream (); * incluencodeparam Param = encoder. getdefajpegincluencodeparam (bufferedimage) image); * Param. setquality (1.0f, true); * encoder. encode (bufferedimage) image, Param); * ImageIO. setusecache (false); ImageIO. write (renderedimage) * image, "jpg", response. getoutputstream (); */} return NULL ;}
/*** @ Author YZH get the default image * @ Param xingbiestr * @ Param URL * @ Param response */private void getdefaultpic (string xingbiestr, File URL, httpservletresponse response) {If (xingbiestr! = NULL) {If ("1 ". equals (xingbiestr) {url = new file (servletactioncontext. getrequest () // female. getsession (). getservletcontext (). getrealpath ("/images/quality/qlovelady.gif");} If ("0 ". equals (xingbiestr) {// male url = new file (servletactioncontext. getrequest (). getsession (). getservletcontext (). getrealpath ("/images/quality/qloveman.gif");} bufferedinputstream Bis = NULL; servletoutputstream sout = NULL; If (UR L! = NULL) {try {Bis = new bufferedinputstream (New fileinputstream (URL); byte [] buffer = new byte [1024*8]; int result =-1; sout = response. getoutputstream (); While (result = bis. read (buffer ))! =-1) {sout. write (buffer, 0, result);} sout. flush ();} catch (exception e) {e. printstacktrace ();} finally {try {bis. close (); sout. close ();} catch (exception ex) {ex. printstacktrace ();}}}}}
// The default image path in the project: