canvas-2 image

How to Store Canvas Image ?

Send request using ajax: var canvas=document.getElementById('can'); var dataURL = canvas.toDataURL("image/png"); var data = { img64:dataURL.replace(/^data:image\/(png|jpg);base64,/, ""), }; $.ajax( { type: 'POST', url: "/FMVMLAST/Canvasimage", data:data, success: function(data){} }); Edit your struts.xml file class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" /> Java class to receive / decode image: import org.apache.commons.codec.binary.Base64; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; public class Canvasimage extends ActionSupport{ private String img64; public byte[] valueDecoded; public String Canvasimage() { setImg64(img64); System.out.println(""+img64); try{ byte[] decoded_id=valueDecoded; FileOutputStream file1 = new FileOutputStream("C:\\image.png"); file1.write(decoded_id); file1.close(); System.out.println("incanvas"+decoded_id); }catch(Exception e){System.out.println("In canvas"+e);} return "success"; } public String getImg64() { return img64; } public void setImg64(String img64) { this.img64 = img64; toImg64Byte(); } private void toImg64Byte() { // TODO Auto-generated method stub byte[] img=img64.getBytes(); this.valueDecoded = Base64.decodeBase64(img); } }  

One thought on “How to Store Canvas Image ?

  1. The subsequent time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I really thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about one thing that you possibly can fix if you werent too busy in search of attention.

Leave a Reply

Your email address will not be published.Required fields are marked *