Android Capture Signature Using Canvas And Save In PNG Image

Android capture signature using canvas example will guide you today.

This example will guide you how to get and save human digital signature in android studio.

After drawing and making the digital signature, we will also save it in the png format.

Final Signature

After all above coding writings, we will get the output as the below video

You can develop digital signature example with two methods.

  1. Using third party libraries on github
  2. And using Canvas Class

We will use second method in this tutorial.

What is Digital Signature

It is mandatory to have some signing documents for several transactions, contracts and business solutions.

In this fast era, getting physical signature on every paper and send that paper to other place or office is little lengthy process.

Digital signature helps us here to simplify this process. User just need to give it’s signature on android device screen instead of real paper. That’s all.

We can save this digital signature as an image and can send it anywhere across the globe.

Now follow all the below steps to create digital signature using canvas in android.

Step 1. Manifest Changes

For storing the image in android device, we need storage permissions.

Write down below two lines in the AndroidManifest.xml file

  • Note : If your app is targeting sdk version greater than 22 then you have to ask for runtime permissions in android.
  • I am targeting sdk version 22, So I have not asked for runtime permissions here.

Step 2. Main Updates

We need to add some source code in the main files to achieve our final goal.

Copy the following source code in activity_main.xml file

  • I have taken one LinearLayout which will work as a signature pad. User will have to write his signature on this pad.
  • LinearLayout with id canvasLL will be our signature pad in the above code.
  • I have also taken two buttons : Clear and Save
  • When the user will click the Clear button, compiler will erase the existing writing from the signature pad.
  • Save button will save the signature in png format when the user will click it.

Write down the following code in file.


Look at the below source code

  • First line will define the String variable DIRECTORY. It is defining a path where we need to create a folder.
  • We will use this variable to create a folder named “Signature” in the external storage.
  • Second line is defining the pic_name String variable. This variable holds the date format in string variable.
  • Third line is defining the StoragePath named String variable. It will completely create a name of the image.

Consider the below code

  • Above line will add view to the signature pad (LinearLayout).
  • Here mSignature is the object of the signature class. We have defined this signature class in the Main Activity itself as written in the above file.

Following code defines the click event of the Clear button.

  • When the user clicks the Clear button, compiler will clear the surface of the signature pad and erase the existing writings.

Look at the below code

  • Compiler will execute the above code when the user will click the save button.
  • It will save the image with the png format in the path defined by the “StoredPath” variable.

clear() and save() method

signature class have two methods clear() and save().

  • clear() method will erase the wrtitings of the signature pad.
  • save() method will save the image in the external storage->Signature directory.

Using canvas class is little complex method as it has very long and deep coding lines.

Customization in this method is a big pain ass you know.

You can use third party library to simplify this process.

Read how to make digital signature in android with library to have simple code.

Download Source Code for Android Capture Signature Using Canvas Example

[sociallocker]Download Source Code for Signature View Example[/sociallocker]

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

1 Response

  1. amin says:

    why not save signature , please help

Leave a Reply

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