Hand written signature control

177 views
Skip to first unread message

Nicola Dell'Amico

unread,
Jul 12, 2013, 2:10:31 AM7/12/13
to codenameone...@googlegroups.com
Hi all,

I'll need to implement a control for acquiring an hand written signature or , in a general form, an hand written drawing and get it as bitmap image.
Is it possible with cross platform code or I need to resort to native code (platform should be android and iOS) ?
Any suggestions ?

thanks
Nicola

Thomas Chatfield

unread,
Jul 12, 2013, 4:10:30 AM7/12/13
to codenameone...@googlegroups.com
This should be possible you could create an Image and then draw onto it using the getGraphics() method.

Nicola Dell'Amico

unread,
Jul 12, 2013, 4:16:54 AM7/12/13
to codenameone...@googlegroups.com
Hi Thomas ,

thank you for the answer bu I'm a bit confused.
Which kind of control did you suggest to pick from the GUI designer pallet to have an Image to draw into ?
It seems to me there is no Image control, may be I have to use a Label with an empty white image to use as drawing canvas; did you mean that ?

Nicola

Thomas Chatfield

unread,
Jul 12, 2013, 7:31:09 AM7/12/13
to codenameone...@googlegroups.com
Hi, didn't realise you was using the UIBuilder.

Not sure how this could be done with the builder. The problem would be the actual drawing of the signature.

In code I would possibly override Label and set the icon to some Image.
Then in the labels pointerDragged() method do the drawing there.


You could draw a small circle via drawArc(), and just move that around to draw the signature.

Tom


Nicola Dell'Amico

unread,
Jul 12, 2013, 8:31:26 AM7/12/13
to codenameone...@googlegroups.com
Hi Tom

thank you very much for the tips.
It isn't a problem to add control on the fly with code into a form created with the UIBuilder , so I'll surely try your solution .

Thanks again

Nicola

Shai Almog

unread,
Jul 12, 2013, 3:32:45 PM7/12/13
to codenameone...@googlegroups.com
Thomas's answer is pretty accurate but just to clarify.
I would derive Component and set the component to focusable true. Then override pointer pressed/dragged/released and whenever I get one of these events just draw a line onto the mutable image.
I would also override paint to just invoke drawImage() with that mutable image.
Override calcPreferredSize() to determine a reasonable size for your component.

A few minor tips:
Override paintBackground/Backgrounds with a blank implementation for improved performance.
Create the image only when needed, make sure the component size is larger than 0 before creating the image with the size of the component.
The component size can change in runtime so you might need to replace the image in such a case.

Nicola Dell'Amico

unread,
Jul 13, 2013, 2:19:07 AM7/13/13
to codenameone...@googlegroups.com
Hi Shai,
thank you very much, I'll try to get it working on the next few days.

Nicola

in...@smsrus.gr

unread,
Oct 25, 2013, 1:59:52 PM10/25/13
to codenameone...@googlegroups.com
Hi Nicola,

I'll probably need the same functionality for my App so I'd like to ask if you have managed to implement this.

Regards

Nicola Dell'Amico

unread,
Oct 29, 2013, 2:45:53 AM10/29/13
to codenameone...@googlegroups.com, in...@smsrus.gr

Hi,

I didn't spent so much time on that because my client has partially lost interest on that, but I wrote a simple Component with very basic functionality, as suggested in previous posts. You can find it as attachment  and you can use it as starting point. Please , don't miss to post any further improvement.

Regards

Nicola
HandWriteComponent.java

Ivan

unread,
Aug 11, 2014, 2:56:17 PM8/11/14
to codenameone...@googlegroups.com, in...@smsrus.gr
Hi all,

I tried to use this component but on iOS it caused memory leaks, here is optimized version. May be it will be helpful for somebody :)

bye

Ivan
HandWriteComponent.java
Reply all
Reply to author
Forward
0 new messages