html
<#-Laden Sie die Avatar-Testseite mit im IMGEEELECT-Plug-in-> hoch->
Schließlich dieses Plugin hochgeladen, um Referenz zu lernen
<link rel = "styleSheet" type = "text/css" href = "$ {Frontres} /imGeaSel/css/imGareasel-animated.css"/> <link rel = "styleSheet" Typ = "text/css type = "text/javaScript" src = "$ {Frontres} /imGeaEasel/jquery-1.4.2.min src = "$ {Frontres} /imGeaEaselect/ajaxFileUpload.js"> </script> function addfile (obj) {//document $ .ajaxFileUpload ({url: '$ {Huluurl}/Trainer/Upload/ajaxUpload', // Die serverseitige Anforderungsadresse für Datei Upload Secureuri: False, // Ob ein Sicherheitsprotokoll erforderlich ist, ist es im Allgemeinen auf falsche Datei-Datei-Datei-Value-Typen-Set-Set-Domain-Datei-Domain-Datei-Domain-Datei-Datei-Domain-Datentypen. JSON -Erfolg: Funktion (Daten) {// Der Server reagiert erfolgreich auf die Verarbeitungsfunktion var infoarray = ("+data+") "). Mit dem Server fehlgeschlagen, versuchen Sie es später erneut! '); } Funktion Vorschau (IMG, Auswahl) {if (! selection.width ||! selection.height) return; // Vorschau var scalex = 100 /selection.width; var scaley = 100 / selection.height; // var imgx = document.getElementById ("foto"). style.width; var imgx = parseInt ($ ("#foto"). CSS ("width"). split ("px") [0]); var imgy = parseInt ($ ("#foto"). CSS ("Höhe"). Split ("px") [0]); console.debug (imgx+"===="+imgy); $ ('#preview img'). $ ('#x1'). Val (Selection.x1); $ ('#y1'). Val (Selection.Y1); $ ('#x2'). Val (Selection.x2); $ ('#y2'). Val (Selection.y2); $ ('#W'). Val (Selection.width); $ ('#H'). Val (Auswahl.Height); // Backend Data $ ('#x1S'). Val (Selection.x1); $ ('#y1s'). Val (Selection.Y1); $ ('#x2S'). Val (Selection.x2); $ ('#y2s'). Val (Selection.Y2); $ ('#imgx'). Val (ParseInt (IMGX)); // Original Breite Breite $ ('#imgy'). Val (ParseInt (IMGY)); // Originalhöhe} $ (Funktion (Auswahl) {var imgx = $ ("#foto"). if (imgx> imgy) {ares = imgy; Selektionsbereich IAs.SetOptions ({Show: True}); / ares; $ ('#x1S'). Val (0); </script> <div style = "margin-top: 20px;"> <div> <div> <div> <div> <h4 style = "Schriftgewicht: 600; float: links"> Das Foto hochladen </h4> </div> <div> <div> <div> <div> <div> <div> links: Hidden; Hintergrundfarbe: #8dc21f; Farbe: #ffffff; "> <span>+Hinzufügen eines Fotos </span> <Eingabe-ID =" Photofile "type =" Datei "name =" PhotoFile "onchange =" addfile (this); "; style = "Höhe: 34px; Position: absolut; rechts: 0px; ober: 0px; Rand: 0px; Polster: 0px; Cursor: Zeiger; Opazität: 0; PNG, and GIF, the size does not exceed 5M</li> </ul> </span> </div> </div> <div> <div> <img src="/images/${(trainer.photo)!""}" id ="img"> </div> </div> </div> </div> <form action = "$ {Huluurl}/Trainer/Upload/UploadPhototest" methode = "post" engTePe = "MultiPart/Form-Data"> <Eingabe type = "text" id = "x1s" name = "x1s" value = "-"/> <eingabe type = "x2s" value = "-" /> <Eingabe type = "text" id = "y2s" name = "y2s" value = "-" /> <input type = "text" id = "imgx" name = "imgx" value = "-" /> <Eingabe type = "text" id = "imgy" name "name" iMGY "iMGY". 80px"> <div> <div> <button type="button"id="chongxinshangchuan">Re-upload</button> </div> <div> <button type="submit" id="baocun"> Save</button> </div> </div> </form> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div id = "root"> <div id = "main"> <div> <div> <div style = "float: links; Breite: 50%; "> <p> Klicken und ziehen Sie das Bild, um einen Bereich auszuwählen. Text-Align: Mitte; Überlauf: versteckt; Z-Index: 1001; Breite: 300px; Höhe: 300px; Position: Relativ; Links: 50%; Top: 50%; Rand -Links: -150px; Rand: -150px; "> <img id =" foto "src ="/images/$ {(Trainer.photo)! ""} "style =" max-height: 300px; max-width: 300px; "/> </div> </div> </div> </div> </div> <div. style =" float: links; Breite: 50%; "> <p style =" Schriftgröße: Schriftgewicht: fett; Padding-Links: 0.1EM; "> Auswahlvorschau </p> <div> <div ID =" Vorschau "> <img Src ="/Bilder/$ {Trainer.photo!} "/> </div> </div> <tabelle> <thead> <tr> <th colspan =" 2 "style =" font-size: 110%; Schriftgewicht: fett; Text-Align: links; Padding-Links: 0,1EM; "> Koordinaten </th> <th colspan =" 2 "style =" Schriftgröße: 110%; Schriftgewicht: fett; Text-Align: links; Padding-Left: 0,1EM; "> Dimensionen </th> </tr> </thead> <tbody> <tr> <td> <b> x <sub> 1 </sub>: </b> </td> <td> <ttds Typ =" text "id =" x1 "value ="-"/> </td> <td> <td> <td> <td> <td> <td> <td> <b> <b> <B> <b> <B> <Bl. type = "text" value = "-" id = "w"/> </td> </tr> <tr> <td> <b> y <sub> 1 </sub>: </b> </td> <td> <Eingabe type = "text" id = "y1" value = "-"/> </td> <td> <b> Höhe: </b> </b> </b> </b> </b> </b> </b> </b> </b> </b> </b> value = "-"/> </td> </tr> <tr> <td> <b> x <sub> 2 </sub>: </b> </td> <td> <Eingabe type = "text" id = "x2" value = "-"/> </td> </td> <td> <td> y <sub> </td> </td> <td> y <td> y </y < </tr> <td><b>Y<sub>2</sub>:</b></td> <td><input type="text" id="y2" value="-" /></td> <td></td> <td></td> </tbody> </table> </div> </div> </div> </div> </div>Java
// Das Bild zeigt einen virtuellen Pfad (tomcat) auf dem Server Server.xml <context debug = "0" docbase = "g:/image" path = "/bilder" reloadable = "true"/> echo Die Daten [java] Ansicht Copy View -Code -Fragmente auf dem Code abgeleitet wurden. "toUploadphoto", method = requestMethod.get) public modelAndView toUploadTest () {modelAndView mav = linksMenu ("/Trainer/Upload/UploadPhoto"); // Trainer Trainer = NULL; try {long userId = frontshiroutil.getUerId (); if (null! = userId) {Trainer = TrainerRrepo.Findone (userId); TrainerDBSVC.UpDatElastLogintime (userID); }} catch (Ausnahme e) {e.printstacktrace (); } mav.addObject ("Trainer", Trainer); MAV zurückgeben; } // Lokale Aktualisieren hochladen Bild @RequestMapping ("/ajaxUpload") public @ResponseBody ajaxResult ajaxUpload (multiparthttpServletRequest -Anforderung) {Trainer Trainer = New Trainer (); // das erste Bild abrufen (die hochgeladene Datei gemäß dem Namen der Rezeption abrufen) MultiPartFile -Datei = Request.getFile ("PhotOFile"); if (file.getSize ()! String timetype = null; if (null! // Die Pfadstring ctxpath = "e:/rudongimage/foto/"; // Dateidatei erstellen DirPath = neue Datei (CTXPath); if (! Dirpath.Exists ()) {Dirpath.Mkdirs (); } // Zeit nehmen als Dateiname Datum Datum = neuer Datum (); SimpleDateFormat SDFormat = new SimpledateFormat ("yyyymmddhhmms"); // 24-Stunden-String lgtime = sdformat.format (Datum); timetype = lgTime + imgType; Datei UploadFile = neue Datei (CTXPath + Timetype); try {filecopyutils.copy (file.getBytes (), UploadFile); } catch (ioException e) {e.printstacktrace (); }} String headphotopath = "photo/" + timetype; Trainer.Setphoto (Headphotopath); } try {// den Trainer basierend auf userID long userId = frontshiroutil.getUerID () abfragen; if (null! = userId) {Trainer.SetUerID (userId); // Aktualisieren Sie den Trainer Avatar Trainerdbsvc.UpdatetrainerPhoto (Trainer); }} catch (Ausnahme e) {e.printstacktrace (); } return ajaxResult.createSuccess (Trainer); // <span style = "Schriftfamilie: Arial, Helvetica, Sans-Serif;"> AjaxResult kann geändert werden. @RequestParam("x1s") Integer x1, @RequestParam("y1s") Integer y1, @RequestParam("x2s") Integer x2, @RequestParam("y2s") Integer y2, @RequestParam("imgx") Integer imgWidth, @RequestParam("imgy") Integer imgHeight) {ModelAndView mav = linkMenu ("redirect:/trainer/upload/topploadphoto"); Trainer Trainer = NULL; Versuchen Sie {// den Trainer basierend auf userID long userID = frontshiroutil.getUerID () abfragen; if (null! = userId) {Trainer = TrainerRrepo.Findone (userId); }} catch (Ausnahme e) {e.printstacktrace (); } Datei uploadFile = new File ("e:/Rudongimage/" + Trainer.getPhoto ()); InputStream ist = null; Bufferedimage src = null; int w = -1; int H = -1; try {is = new FileInputStream (UploadFile); src = javax.imageo.imageio.read (IS); w = src.getwidth (null); // die Quellbildbreite abrufen h = src.getheight (null); // Die Quellgrafikhöhe is.CLOSE () erhalten; } catch (Ausnahme e) {e.printstacktrace (); } Integer L = 0; // kleine Kanten als Grundlage (Originalbildgröße) verwenden, wenn (w <h) {l = w; } else {l = h; } // kleine Kanten als Grundlage (Miniaturansichtengröße) Integer L2 = 0 verwenden; if (imgwidth <imgHeight) {l2 = imgwidth; } else {l2 = imgHeight; } Integer x = (x1 * l)/ l2; // Ausgangspunkt x Integer y = (y1 * l)/ l2; // Ausgangspunkt y Integer xs = (x2 * l)/ l2; // Endpunkt x diagonale Position Integer ys = (y2 * l)/ l2; // Endpunkt y diagonales Bildungsbild = New Imageil () () (diagonale Position y diagonal pageil bildutil) bildutil = new pageil () () (diagonale Position y diagonal pageil bildutil = new pageil () () (diagonale Position y diagonal pageil bildutil = new pageil () () (diagonale Position) bildutil = new pageil () () (diagonale Position y diagonal pageil imageutil // Rückgabe des abgefangenen Dateinamens String Photoname = ""; ImageUtil.cutimage (UploadFile, "E:/Rudongimage/Foto/", x, y, xs - x, ys - y); String Headphotopath = "Foto/" + Photoname; Trainer.Setphoto (Headphotopath); // Aktualisieren Sie den Avatar Trainerdbsvc.UpdatetrainerPhoto (Trainer); MAV zurückgeben; }Werkzeuge
Import Java.awt.Color; importieren java.awt.graphics; import Java.awt.image; Import Java.awt.Rectangle; Import Java.awt.image.BuffenedImage; Import Java.io.file; import Java.io.FileInputStream; importieren java.io.filenotfoundException; importieren java.io.ioException; importieren java.io.inputstream; importieren java.io.outputstream; Import Java.util.Arrays; Import Java.util.iterator; import Javax.imageo.imageo; importieren javax.imageo.imagereadParam; importieren javax.imageo.imagereader; import Javax.imageo.stream.imageInputStream; import org.slf4j.logger; import org.slf4j.loggerfactory; / *** Image Interceptor Tool Class*/ öffentliche Klasse ImageUtil {private logger log = loggerfactory.getLogger (getClass ()); private statische String default_thumb_prevfix = "thumb_"; private statische String default_cut_prevfix = "cut_"; private static boolean default_force = false; /*** <P> Titel: Cutimage </p>* <p> Beschreibung: Abfangen lokale Bilder basierend auf dem Originalbild und der Pflanzengröße </p>* @param srcimg Source Image* @param Ausgabe -Ausgangsstrom. if (srcimg.exists ()) {java.io.fileinputStream fis = null; ImageInputStream iis = null; try {fis = new FileInputStream (SRCIMG); // Imageio unterstützt Bildtypen: [BMP, BMP, JPG, JPG, WBMP, JPEG, PNG, PNG, JPEG, WBMP, GIF, GIF] String -Typen Typen = Arrays.toString (Imageio.getreaderFormatnames ()). String -Suffix = null; // das Bild -Suffix if (srcimg.getName (). Indexof (".")> -1) {suffix = srcimg.getname (). Substring (srcimg.getName (). LastIndexof (") + 1); } // Typ- und Bildsuffix sind alle Kleinigkeiten und bestimmen dann, ob das Suffix legal ist, wenn (suffix == null || typen.tolowerCase (). Indexof (Suffix.tolowerCase () + ",") <0) {log.info ("sorry, das Bild -Suffix ist illegal. Das Standard -Bildsuffix ist {{}." + Typen); zurückkehren ; } // FileInputStream in ImageInputStream IIS = ImageIo.CreateImageInputStream (FIS) konvertieren; // Imaglereader dieses Typs entsprechend dem Bildtyp ImaglereAder reader = imageio.getImagereAlsBysuffix (Suffix) .Next (); Reader.SetInput (IIS, True); ImageReADparam param = reader.getDefaultreadParam (); Param.SetSourCeregion (rect); Bufferedimage bi = reader.read (0, param); Imageio.Write (bi, Suffix, Ausgabe); } catch (FilenotFoundException e) {e.printstacktrace (); } catch (ioException e) {e.printstacktrace (); } endlich {try {if (fis! = null) fis.close (); if (iis! = null) iis.close (); if (output! = null) output.close (); } catch (ioException e) {e.printstacktrace (); }}}} else {log.info ("Das SRC -Bild ist nicht existiert."); }} public void Cutimage (Datei srcimg, outputStream output, int x, int y, int width, inthohe) {Cutimage (Srcimg, Ausgabe, neuer java.awt.Rectangle (x, y, width, Höhe)); } public void Cutimage (Datei SRCIMG, String destimgPath, java.awt.Rectangle rect) {Datei destimg = neue Datei (DestimgPath); if (destimg.exists ()) {string p = destimg.getPath (); try {if (! destimg.isdirectory ()) p = destimg.getParent (); if (! p.endswith (Datei.Sesparator)) p = p + file.separator; Cutimage (srcimg, new java.io.fileOutputStream (p + default_cut_prevfix + "_" + new java.util.date (). GettTime () + "_" + srcimg.getName ()), rechteweise); } catch (FilenotFoundException e) {log.info ("Das Dest -Bild ist nicht existiert."); }} else log.info ("Der Dest -Bildordner gibt es nicht."); } public void Cutimage (Datei srcimg, String destimg, int x, int y, int width, int Höhe) {Cutimage (srcimg, destimg, new Java.awt.Rectangle (x, y, width, Höhe)); } public void Cutimage (String srcimg, String destimg, int x, int y, int width, int Höhe) {Cutimage (neue Datei (srcimg), destimg, neu java.awt.Rectangle (x, y, width, Höhe)); }/*** <p> Titel: Miniaturimage </p>* <p> Beschreibung: Erzeugen Sie Thumbnails basierend auf Bildpfad </p>* @param ImagePath Original Bildweg* @param wesumathumme Breite* @param h. the best scale thumbnail is generated) */ public void thumbnailImage(File srcImg, OutputStream output, int w, int h, String prevfix, boolean force){ if(srcImg.exists()){ try { // ImageIO Supported image types: [BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, GIF] String -Typen = arrays.toString (imageIO.getreaderFormatNames ()). Ersetzen ("]", ","); String -Suffix = null; // das Bild -Suffix if (srcimg.getName (). Indexof (".")> -1) {suffix = srcimg.getname (). Substring (srcimg.getName (). LastIndexof (") + 1); } // Typ- und Bildsuffix sind alle Kleinigkeiten und bestimmen dann, ob das Suffix legal ist, wenn (suffix == null || typen.tolowerCase (). Indexof (Suffix.tolowerCase () + ",") <0) {log.info ("sorry, das Bild -Suffix ist illegal. Das Standard -Bildsuffix ist {{}." + Typen); zurückkehren ; } log.info ("Größe des Zielbildes, Breite: {}, Höhe: {}.", W, H); Bild img = imageio.read (srcimg); // Finden Sie die am besten geeignete Miniaturansichtskala basierend auf dem Originalbild und der erforderlichen Miniaturansichtskala, wenn (! Kraft) {int width = img.getwidth (null); int height = img.getheight (null); if ((width*1.0)/w <(Höhe*1.0)/h) {if (width> w) {h = integer.parseInt (new java.text.decimalFormat ("0"). Format (Höhe*w/(Width*1.0)); log.info ("Bildhöhe ändern, Breite: {}, Höhe: {}.", W, H); }} else {if (Höhe> h) {w = integer.parseInt (new java.text.decimalFormat ("0"). Format (width * h/(Höhe * 1.0)); log.info ("Bildungsbild widmen, width: {}, Höhe: {{}. PufferedImage.type_int_rgb); System.out.println ("Daumenbild erzeugen."+E); if (! srcimg.isdirectory ()) p = srcimg.getParent (); (FilenotFoundException e) {log.info ("Das Dest -Bild ist nicht existiert."+E); }} public void thumbnailImage (String ImagePath, int W, int H, String prevfix, boolesche Kraft) {Datei srcimg = new Datei (ImagePath); Thumbnailimage (Srcimg, W, H, Prevfix, Force); } public void thumbnailimage (String ImagePath, int W, int H, boolean Force) {thumbnailimage (ImagePath, W, H, default_thumb_prevfix, default_force); } public void thumbnailimage (String ImagePath, int w, int h) {thumbnailimage (ImagePath, W, h, default_force); } public void ReadingImagereeAder (String SRC, String dest, int w, int h) löst Ausnahme aus {// den Bildleser iterator readers = imageIO.getImagereAlsByFormatName ("PNG"); ImageReader reader = (Imagereader) readers.Next (); // den Image Reader -Zufluss inputStream Source = new FileInputStream (SRC) abrufen; ImageInputStream iis = imageIO.CreateimageInputStream (Quelle); Reader.SetInput (IIS, True); // Bildparameter imagereadParam param = reader.getDefaultreadParam (); // 100, 200 ist die Ausgangsposition am oberen linken, 300 ist die Breite von 300, was 300 von 100 liegt, was horizontal 100 ~ 400 ist. In ähnlicher Weise nimmt die Fläche von 200 ~ 350 vertikal die Höhe von 150 // Rechteck rechteck = neues Rechteck (100, 200, 300, 150); // int HH = 0; if (h> 100) hh = (h - 100) / 3; Rechteck rechteck = neues Rechteck (0, HH, 227, 100); Param.SetSourCeregion (rect); Bufferedimage bi = reader.read (0, param); Imageio.write (bi, "jpg", neue Datei (dest)); } public static void main (String [] args) löst eine Ausnahme aus {// New ImageUtil (). Thumbnailimage ("imgs/tulips.jpg", 150, 100); // New ImageUtil (). Cutimage ("IMGS/Tulips.jpg", "IMGS", 250, 70, 300, 400); // New ImageUtil (). ReadingImagereeAder ("e: //rudongimage/photo/20160302090226.png", "e: //rudongimage/photo/2.png", 227, 163); }}XML -Konfiguration
<bean id = "multipartresolver" class = "org.springframework.web.multipart.Commons.CommonsMultipartresolver"> <!- Eine der verfügbaren Eigenschaften; Die maximale Dateigröße in Bytes <Eigenschaft name = "maxUploadsize" value = "9999999999"/>-> </bean>
Plugin -Verbindung
http://download.csdn.net/download/U014596302/9572377
Es gibt einige hässliche Funktionen, wenn der Stil nicht angepasst wird.