-2

My application has a requirement where the user can write their signature on the screen. The signature should be able to be extracted into an image.

How should I go about this ?

Is there an existing android process/observer for this ? Or are they any libraries / plugins that might allow the functionality ?

Prakash Raman
  • 13,319
  • 27
  • 82
  • 132

1 Answers1

0

use this code in Activity:

  try {
        GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.signaturePad);
        gestureView.setDrawingCacheEnabled(true);
        Bitmap bm = Bitmap.createBitmap(gestureView.getDrawingCache());
        File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "signature.png");
        f.createNewFile();
        FileOutputStream os = new FileOutputStream(f);
        os = new FileOutputStream(f);
        //compress to specified format (PNG), quality - which is ignored for PNG, and out stream
        bm.compress(Bitmap.CompressFormat.PNG, 100, os);
        os.close();

    } catch (Exception e) {

        Log.v("Gestures", e.getMessage());
        e.printStackTrace();
    }
}

In xml:

<android.gesture.GestureOverlayView
        android:id="@+id/signaturePad"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:background="@android:color/white"
        android:eventsInterceptionEnabled="true"
        android:fadeEnabled="false"
        android:gestureColor="@android:color/black"
        android:gestureStrokeLengthThreshold="0.1"
        android:gestureStrokeType="multiple"
        android:orientation="vertical"/>
Krishna V
  • 1,801
  • 1
  • 14
  • 16