Here's how I have capture human signature and save image using this example:
https://demonuts.com/android-capture-digital-signature/
First add following to your gradle:
repositories {
jcenter()
}
repositories {
maven {
url 'https://dl.bintray.com/zahid/maven/'
}
}
dependencies {
compile 'com.kyanogen.signatureview:signature-view:1.0'
}
activity_main.xml:
MainActivity.java:
package com.example.parsaniahardik.signaturedemo;
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.kyanogen.signatureview.SignatureView;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
Bitmap bitmap;
Button clear,save;
SignatureView signatureView;
String path;
private static final String IMAGE_DIRECTORY = "/signdemo";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
signatureView = (SignatureView) findViewById(R.id.signature_view);
clear = (Button) findViewById(R.id.clear);
save = (Button) findViewById(R.id.save);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signatureView.clearCanvas();
}
});
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bitmap = signatureView.getSignatureBitmap();
path = saveImage(bitmap);
}
});
}
public String saveImage(Bitmap myBitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
File wallpaperDirectory = new File(
Environment.getExternalStorageDirectory() + IMAGE_DIRECTORY /*iDyme folder*/);
// have the object build the directory structure, if needed.
if (!wallpaperDirectory.exists()) {
wallpaperDirectory.mkdirs();
Log.d("hhhhh",wallpaperDirectory.toString());
}
try {
File f = new File(wallpaperDirectory, Calendar.getInstance()
.getTimeInMillis() + ".jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
MediaScannerConnection.scanFile(MainActivity.this,
new String[]{f.getPath()},
new String[]{"image/jpeg"}, null);
fo.close();
Log.d("TAG", "File Saved::--->" + f.getAbsolutePath());
return f.getAbsolutePath();
} catch (IOException e1) {
e1.printStackTrace();
}
return "";
}
}
Don't forget to give READ-WRITE permission in manifest.xml