Hi, I am using ti.paint module on android and ios. I want to use this module to make signature of a user and then send those signature to server after doing base 64 encoding. The complete functionality works for iOS but it does not work for android.
On server side, I am using java program to decode the base64 encoded sign image file. The program is able to retrieve the signature image on server for iOS encoded strings but not for android encoded string, it generate the image but only canvas (no signature) is retained.
I am putting both programs here..
Ti mobile app sample code
var Paint = require('ti.paint'); var win = Titanium.UI.createWindow({ layout:'vertical', backgroundColor:"white" }); signImageView = Ti.UI.createImageView({ top:'50dp', image:'/images/1.png' }); win.add(signImageView); paintView = Paint.createPaintView({ top:'10dp', backgroundColor:'#fff', height:'150', width:'150', strokeColor:'#000', strokeAlpha:255, strokeWidth:1, eraseMode:false, borderColor:"gray", borderWidth:'1dp' }); win.add(paintView); var btn = Ti.UI.createButton({ title:"click", top:10 }); win.add(btn); btn.addEventListener('click', function () { if (OS_IOS) { var sign = paintView.toImage(); signImageView.image = sign; encodedSignature = Ti.Utils.base64encode(sign).toString(); Ti.API.info('iOS Signature base64 encoded = ' + encodedSignature); } else { var sign = paintView.toImage().media; signImageView.image = sign; encodedSignature = Ti.Utils.base64encode(sign).toString(); Ti.API.info('Android Signature base64 encoded = ' + encodedSignature); } }); win.open();
server side java program to decode the signature and write to a file. I can retrieve images signed on iOS app but not on android app.
import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; //import java.nio.file.Files; import com.sun.jersey.core.util.Base64; import javax.imageio.ImageIO; import sun.misc.BASE64Decoder; public class Decoder { public static void main(String[] args) { try{ String imageByteArr = "<<copy the mobile app generated base 64 string here>>"; BASE64Decoder decoder = new BASE64Decoder(); byte[] bytearray = decoder.decodeBuffer(imageByteArr); File file = new File("/Users/Virendra/snap.png"); FileOutputStream fop = new FileOutputStream(file); fop.write(bytearray); fop.flush(); fop.close(); System.out.println("ok"); }catch (Exception ex){ ex.printStackTrace(); } } }