android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java
final void saveImage() {

		String root = Environment.getExternalStorageDirectory().toString();

		// the directory where the signature will be saved
		File myDir = new File(root + "/saved_signature");

		// make the directory if it does not exist yet
		if (!myDir.exists()) {
			myDir.mkdirs();
		}

		// set the file name of your choice
		String fname = String.format("signature_%d.png", System.currentTimeMillis());

		// in our case, we delete the previous file, you can remove this
		File file = new File(myDir, fname);
		if (file.exists()) {
			file.delete();
		}

		try {

			Log.d("React Signature", "Save file-======:" + saveFileInExtStorage);
			// save the signature
			if (saveFileInExtStorage) {
				FileOutputStream out = new FileOutputStream(file);
				this.signatureView.getSignature().compress(Bitmap.CompressFormat.PNG, 90, out);
				out.flush();
				out.close();
			}

			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
			Bitmap resizedBitmap = getResizedBitmap(this.signatureView.getSignature());
			resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);

			byte[] byteArray = byteArrayOutputStream.toByteArray();
			String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

			WritableMap event = Arguments.createMap();
			event.putString("pathName", file.getAbsolutePath());
			event.putString("encoded", encoded);
			event.putString("uri", this.getImageContentUri(file).toString());
			
			ReactContext reactContext = (ReactContext) getContext();
			reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/**
	 * save the signature to an sd card directory
	 */
save the signature to an sd card directory
save the signature to an sd card directory
final void saveImage() {
		String root = Environment.getExternalStorageDirectory().toString();
		File myDir = new File(root + "/saved_signature");
		if (!myDir.exists()) {
			myDir.mkdirs();
		}
		String fname = String.format("signature_%d.png", System.currentTimeMillis());
		File file = new File(myDir, fname);
		if (file.exists()) {
			file.delete();
		}
		try {
			Log.d("React Signature", "Save file-======:" + saveFileInExtStorage);
			if (saveFileInExtStorage) {
				FileOutputStream out = new FileOutputStream(file);
				this.signatureView.getSignature().compress(Bitmap.CompressFormat.PNG, 90, out);
				out.flush();
				out.close();
			}
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
			Bitmap resizedBitmap = getResizedBitmap(this.signatureView.getSignature());
			resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
			byte[] byteArray = byteArrayOutputStream.toByteArray();
			String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
			WritableMap event = Arguments.createMap();
			event.putString("pathName", file.getAbsolutePath());
			event.putString("encoded", encoded);
			event.putString("uri", this.getImageContentUri(file).toString());
			ReactContext reactContext = (ReactContext) getContext();
			reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
final void saveImage ( ) { String root = Environment . getExternalStorageDirectory ( ) . toString ( ) ; File myDir = new File ( root + "/saved_signature" ) ; if ( ! myDir . exists ( ) ) { myDir . mkdirs ( ) ; } String fname = String . format ( "signature_%d.png" , System . currentTimeMillis ( ) ) ; File file = new File ( myDir , fname ) ; if ( file . exists ( ) ) { file . delete ( ) ; } try { Log . d ( "React Signature" , "Save file-======:" + saveFileInExtStorage ) ; if ( saveFileInExtStorage ) { FileOutputStream out = new FileOutputStream ( file ) ; this . signatureView . getSignature ( ) . compress ( Bitmap . CompressFormat . PNG , 90 , out ) ; out . flush ( ) ; out . close ( ) ; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; Bitmap resizedBitmap = getResizedBitmap ( this . signatureView . getSignature ( ) ) ; resizedBitmap . compress ( Bitmap . CompressFormat . PNG , 100 , byteArrayOutputStream ) ; byte [ ] byteArray = byteArrayOutputStream . toByteArray ( ) ; String encoded = Base64 . encodeToString ( byteArray , Base64 . DEFAULT ) ; WritableMap event = Arguments . createMap ( ) ; event . putString ( "pathName" , file . getAbsolutePath ( ) ) ; event . putString ( "encoded" , encoded ) ; event . putString ( "uri" , this . getImageContentUri ( file ) . toString ( ) ) ; ReactContext reactContext = ( ReactContext ) getContext ( ) ; reactContext . getJSModule ( RCTEventEmitter . class ) . receiveEvent ( getId ( ) , "topChange" , event ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
save the signature to an sd card directory
save the signature to an sd card directory
// the directory where the signature will be saved // make the directory if it does not exist yet // set the file name of your choice // in our case, we delete the previous file, you can remove this // save the signature