Dalam proyek ini, kita perlu melakukan beberapa pengunggahan avatar, fungsi pemotongan gambar, OK baca artikel berikut!
Saya perlu plug -in: jQuery jcrop
Kode Kembali -End:
Paket .imageio.imageio; Param Path2 Path yang disimpan setelah pemotongan* @param xx poros* @param yy poros* @param w* @param h*/ cutimage statis public static (string path1, string path2, int x, int y, int w, int h) {FileInputStream FileInputStream = NULL; "JPG"); ).; ("Cutting Failure");} akhirnya {coba (file inputStream! = Null) {fileInputStream.close ();} if (is! = Null) {iis.close ();}} catch (ioExcetion e) {e. printStackTrace ();}}}}}}}}}}}}}}
Kode akses:
<%@page language = "java" import = "java.util.*, org.csg.upload.*" pageEncoding = "UTF-8"%> <%// string jalur relatif er (er "imgpath") ; server setelah memotong string path2 = relpath+"/gambar/"+newfileName; Integer.parseint (request.getParameter ("w"); int h = integer.parseint (request.getParameter ("h"); coba {unggah.c.c utimage (path1, path2, x, y, w, h); out. .print ("<img src = 'gambar/"+newfileName+"'/>");} catch (Exception e) {e.printstacktrace ();
Kode JSP:
<%@ halaman bahasa = "java" gambar = "java.util.*" pageEncoding = "UTF-8"%> <! JSP Kembangkan pemotongan avatar </itement> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-control" content = "no-cache"> <meta http-equiv = "Expires" content = "0"> <meta http-equiv = "kata kunci" konten = "kata kunci1, kata kunci2, kata kunci3"> <meta http-equiv = "deskripsi ption" content = "Ini halaman saya"> <tautan rel = "stylesheet" href = "css/jQuery.jcrop.css" type = "text/css"/> <script type = "text/javascript" src = "js/jQuery.min.js"> </script> <type skrip = "text/javascript" src = "js/jquery.jcrop.min.js"> </script> <alle type = "text/css"> *{margin: 0; {margin-top: 20px;} #Pratinjau {display: block 0 .4) Solid; ); } </tyle> <script type = "text/javascript"> nction () {var jcrop_api, boundx = "", boundy = "", $ preview = $ ('#preview-pane'), $ pcnt = $ ( '#Preview-Pane .Preview-Container'), $ pimg = $ ('#Preview-Pane .Preview-Controlainer IMG'), xsize = $ pcnt.width (), ysize = $ pcnt.head (); '#cutimage') (Jcrop_api.ui.holder);}); $ (#y1 "). ; Math.round (rx * cx) + 'px', margintop: ' + math.round (ry * cy) +' px '});}}}); > Pengembangan Java QQ Avatar Cutting System </h1> <img id = "cutimage" src = "gambar/1.jpg"> <div id = "preview-pane"> <Div> <img src = "gambar/1. jpg "/> </div> </div> </div> <form action =" success.jsp "method =" Post "> <input type =" text "value =" gambar/1.jpg "name =" IMGPATH "> X Sumbu: <Input type =" Text "size =" 4 "id =" x1 "name =" x " /> y Sumbu: <input type =" text "size =" 4 "id =" y1 " name = "y"/> lebar: <input type = "text" size = "4" id = "w" name = "w"/> tinggi: <input type = "text" size = "4" id = " h "name =" h "/> <input type =" kirim "value =" cut "/> </form> </body> </html>
Efek Peta:
Di atas adalah semua isi artikel ini.