Base64 signature capture as black square box in Codenameone App

1

I'm using Signature capture in Mobile App and most of the time it works correct. I have offline capability for the App s o when the App is in offline mode, signature is captured and while sending to the server the image is going as black square.This is due to any data corruption at the mobile level or any issue in using the signature API. Please advise.

Code:

Image sourceImage = sign.getSignatureImage().scaledSmallerRatio(300, 100);
Image mute = Image.createImage(sourceImage.getWidth(), sourceImage.getHeight(), 0xffffffff);
Graphics g = mute.getGraphics();
g.drawImage(sourceImage, 0, 0);
test.setSignature(mute);
Base64.encodeNoNewline(EncodedImage.createFromImage(test.getSignature(), 
false).getImageData())

Questions:

  1. New Code leads to white spaces in the signature also. Signature looks like not renderingly properly. Please advise.

  2. What is the code if I have to send the image as PNG to the server. I'm using following code: Base64.encodeNoNewline(EncodedImage.createFromImage(act.getSignature(), false).getImageData())

base64
codenameone
asked on Stack Overflow Apr 26, 2018 by Chris L • edited Jun 6, 2018 by Chris L

1 Answer

0

Make sure you are saving the image file as a PNG and not as a JPEG. The image file might contain transparency and some JPEG encoders might fail in that case.

To make the image "jpegable" (totally made that up right now) you can do the following:

// white mutable image
Image mute = Image.create(sourceImage.getWidth(), sourceImage.getHeight, 0xffffffff);
Graphics g = mute.getGraphics();
g.setAntiAliased(true);
g.drawImage(sourceImage, 0, 0);

Now you can save mute as a JPEG since it's an opaque white image. The black signature will appear correctly on top of that.

answered on Stack Overflow Apr 27, 2018 by Shai Almog • edited May 2, 2018 by Shai Almog

User contributions licensed under CC BY-SA 3.0