Dans le projet, nous devons faire des avatars à télécharger, des fonctions de coupe d'images, ok lire l'article suivant!
J'ai besoin de plug -in: jquery jcrop
Back -end Code:
Org.csg.upload; .Imageio.imageio; Param Path2 Le chemin stocké après la coupe * @param xx arbre * @param yy arbre * @param w * @param h * / public static void Cutimage (String Path1, String Path2, int x, int y, int w, int h) {FileInputStream FileInputStream = null; ImageInputStream iis = null; "JPG"); ).; ("Échec de coupe");} enfin {try (file inputStream! = Null) {fileInputStream.close ();} if (is! = Null) {iis.close ();}} catch (ioexcetion e) {e. printStackTrace ();}}}}}}}}}}}}}}
Code d'accès:
<% @ Page Language = "Java" import = "java.util. *, org.csg.upload. *" Pageencoding = "utf-8"%> <% // La chaîne de chemin relative ER (er "imgpath") ; String Relpath = request.getRealPath ("/"); le serveur après la coupe de la chaîne PATH2 = RelPath + "/ Images /" + newFileName; int x = Integer.Parseint ("request.getParameter (" x ")); nteger.parseInt (request .getParameter (" y "); int w = Integer.ParseInt (request.getParameter ("W"); int h = Integer.ParseInt (request.getParameter ("h"); try {upload.c.c utimage (path1, path2, x, y, w, h); out .print ("<img src = 'images /" + newFileName + "' />");} catch (exception e) {e.printStackTrace ();
Code jsp:
<% @ Page Language = "Java" Image = "Java.util. *" Pageencoding = "UTF-8"%> <! Jsp développe Avatar Cutting </Title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-control" content = "no-cache"> <meta http-equiv = "Expires" content = "0"> <meta http-equiv = "keywords" contenu = "keyword1, keyword2, keyword3"> <meta http-equiv = "description ption" contenu = "Ceci est ma page"> <lien rel = "Stylesheet" href = "css / jQuery.jcrop.css" type = "text / css" /> <script type = "text / javascript" src = "js / jquery.min.js"> </ script> <Script Type = "Text / JavaScript" Src = "JS / jQuery.jcrop.min.js"> </ script> <alls type = "Text / CSS"> * {margin: 0; ? 0, .4) Solide; )); -moz-box-shadow: 1px 1px 5px 2px rgba (0, 0, 0,2); } </ style> <script type = "text / javascript"> nction () {var jcrop_api, boundx = "", boundy = "", $ aperview = $ ('# préview-poane'), $ pcnt = $ ( '# Aperçu-Pane .Preview-Container'), $ pimg = $ ('# Aperçu-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 '});}}}); > Java Development QQ Avatar Cutting System </h1> <img id = "Cutimage" src = "images / 1.jpg"> <div id = "préview-poane"> <div> <img src = "images / 1. jpg "/> </ div> </ div> </ div> <form action =" Success.jsp "méthode =" post "> <input type =" text "value =" images / 1.jpg "name =" Imgpath "> x axe: <input type =" text "size =" 4 "id =" x1 "name =" x "/> y axe: <input type =" text "size =" 4 "id =" y1 " name = "y" /> width: <input type = "text" size = "4" id = "w" name = "w" /> height: <input type = "text" size = "4" id = " h "name =" h "/> <input type =" soumi "value =" cut "/> </ form> </ body> </html>
Carte d'effet:
Ce qui précède est tout le contenu de cet article.