En el proyecto, necesitamos hacer algunos avatares cargando, las funciones de corte de imágenes, ¡OK, lee el siguiente artículo!
Necesito plug -in: jQuery jcRop
Código de back -end:
paquete org.csg.uplaad; .Image.Imageio; Param Path2 La ruta almacenada después de cortar* @param xx eje* @param yy eje* @param w* @param h*/ public static void cuaMage (string path1, string path2, int x, int y, int w, int h) {FileInputStream FileInputStream = NULL; "JPG"); ).; ("Corte de falla");} Finalmente {try (File InputStream! = NULL) {fileInputStream.close ();} if (is! = Null) {iis.close ();}} catch (ioexcetion e) {e. printStackTrace ();}}}}}}}}}}}}}}
Código de acceso:
<%@page lenguaje = "java" import = "java.util.*, org.csg.upload.*" pageEncoding = "utf-8"%> <%// La cadena de ruta relativa er (er "imgpath") ; El servidor después de cortar string path2 = relpath+"/images/"+newFileName; Integer.ParseInt (request.getParameter ("w"); int h = integer.ParseInt (request.getParameter ("h"); try {ifoad.c.c utimage (path1, path2, x, y, w, h); out .print ("<img src = 'images/"+newFileName+"'/>");} Catch (Exception e) {E.PrintStackTrace ();
Código JSP:
<%@ page lenguaje = "java" image = "java.util.*" PageEncoding = "utf-8"%> <! JSP Desarrollar el corte de avatar </title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-confontrol" content = "no-cache"> <meta http-oquiv = "Expires" Content = "0"> <meta http-equiv = "Palabras clave" Content = "Keyword1, Keyword2, Keyword3"> <meta http-equiv = "Descripción Ption" Content = "Esta es mi página"> <Link rel = "stylesheet" href = "css/jQuery.jcRrop.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> <alle tipo = "text/css"> *{margen: 0; {Margin-top: 20px;} #Preview-Pane {Block: 0, .4) Color de fondo; ); } </style> <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. $ ("#y1"). ; Math.round (rx * cx) + 'px', margintop: ' + math.round (ry * cy) +' px '});}}}); > Java Development QQ Avatar System </h1> <img id = "cutImage" src = "imágenes/1.jpg"> <div id = "Preview-pane"> <div> <img src = "Images/1. jpg "/> </div> </div> </div> <form de acción =" éxito.jsp "método =" post "> <input type =" text "value =" imágenes/1.jpg "name =" Imgpath "> x eje: <input type =" text "size =" 4 "id =" x1 "name =" x " /> y eje: <input type =" text "size =" 4 "id =" y1 " name = "y"/> width: <input type = "text" size = "4" id = "w" name = "w"/> altura: <input type = "text" size = "4" id = " H "name =" h "/> <input type =" envíe "value =" CUT "/> </form> </body> </html>
Mapa de efecto:
Lo anterior es todo el contenido de este artículo.