Function: For some pages of the chat class, the chat record is sent to the server side.
The JS frame used:
Imgareaselect
http://odyniec.net/projects/imgareaselect/
Html2canvas
http://html2canvas.hertzen.com/
Use the Imageareaselect plugin to generate Cancas and upload content to the server using Html2cancas
Interface:
Front-end JS script
$ (function () {var _width = 0;var _height = 0;var _bordercss;function imagecutcancel () {alert (_BORDERCSS)}$ ("#btnCut"). On (' click ', Function () {_BORDERCSS = $ (' #photo01 '). Get (0). style.border;$ (' #photo01 '). CSS (' border ', ' 1px solid #FF0000 ') . Imgareaselect ({handles:true, Onselectend:function (IMG, selection) {_width = Selection.width; _height = Selection.height; $ (' input[name= ' x1 "]). Val (selection.x1); $ (' Input[name=" y1 "] '). Val (selection.y1); $ (' Input[name=" x2 "] '). Val ( SELECTION.X2); $ (' Input[name= "y2"] '). Val (selection.y2); } }); }); $ ("#btnCancel"). On (' click ', Function () {_width = 0;_height = 0;$ (' #photo01 '). CSS (' border ', _bordercss). Imgareaselect ({remove:true});}); $ ("#btnOk"). On (' click ', function () {if (_width<10 && _height<10) return False;html2canvas ($ (' div# Photo01 '), {onrendered:function (canvas) {var imgcxt = Canvas.todataurl (); $.post (' ${pagecontext.request.contextpath} /image/upload.do ', {"Data": Imgcxt}, Function (JSON) {alert (JSON.MSG);}, ' json ');d ocument.body.appendChild (canvas);},width: _width,height: _height}); $ ("#btnCancel"). Click ();});}); Java Script
@Controller @requestmapping ("/image") public class imagecontroller{@RequestMapping ("/upload") public void Uplod ( HttpServletRequest request, HttpServletResponse response) {String data = Request.getparameter ("data"); int result = 1; String msg = "Upload succeeded"; Base64 base64 = new Base64 ()//base64 decode imagebyte[] b = Base64.decode (Data.substring ("Data:image/png;base64,". Length ()). GetBytes ()); String fileName = string.valueof (System.currenttimemillis ()),//image pathstring FilePath = System.getproperty (" Zokee.root ") + File.separator +" DATAS "+ file.separator + fileName +". png ";//write imagefile file = new file (filePath); t ry {fileutils.writebytearraytofile (file, b);} catch (IOException e) {result = 0;msg = "Upload Failed"; E.printstacktrace ();} Jsonobject json = new Jsonobject (); Json.accumulate ("result", result); Json.accumulate ("msg", MSG); Response.setcontenttype ("Text/json"); Response.setcharacterencoding ("Utf-8"); try {printwriter out = Response.getwriter (); Out.print (json.tostring ());} catch (IOException e) {e.Printstacktrace ();}}}
Reference article: http://leobluewing.iteye.com/blog/2020145
Html2canvas uploading images to the server (Java)