如何捕获人类签名

发布于 2024-11-26 14:15:56 字数 1436 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

叹沉浮 2024-12-03 14:15:56

这是一个模糊的想法:

  1. 您需要一个可以允许用户在屏幕上绘图的画布对象。这是关于它的链接。 Android 绘制一条线来跟随手指

  2. 然后您需要将该位图输出为文件:将位图保存到位置

Here is a vague idea:

  1. You'll want to have a canvas object that can allow the user to draw to the screen. Here is a link on SO about it. Android drawing a line to follow your finger

  2. Then you'll want to output that bitmap as a file: Save bitmap to location

美人骨 2024-12-03 14:15:56

您可以通过两种方式执行此操作:

1.您自己的实现

您可以使用canvas来绘制签名。使用绘画对象设置签名笔画大小和签名颜色。

2.只需使用库

请参阅SignatureView库。它会做你想要的一切。

https://github.com/zahid-ali-shah/SignatureView

You can do this in two ways:

1. Your own Implementation

You can use canvas to draw signatures. Use paint object to set signature stroke size & color.

2. Simply use library

See SignatureView library. It will do all, what you want.

https://github.com/zahid-ali-shah/SignatureView

云仙小弟 2024-12-03 14:15:56

以下是我如何使用此示例捕获人类签名并保存图像:

https://demonuts.com /android-capture-digital-signature/

首先将以下内容添加到您的gradle中:

 repositories {
        jcenter()
  }

  repositories {
      maven {
          url 'https://dl.bintray.com/zahid/maven/'
      }
  }

  dependencies {
      compile 'com.kyanogen.signatureview:signature-view:1.0'
  }

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.parsaniahardik.signaturedemo.MainActivity">

    <com.kyanogen.signatureview.SignatureView
        xmlns:sign="http://schemas.android.com/apk/res-auto"
        android:id="@+id/signature_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        sign:penSize="5dp"
        sign:backgroundColor="#ffffff"
        sign:penColor="#000000"
        sign:enableSignature="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/clear"
        android:text="clear"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/save"
        android:text="save"/>
</LinearLayout>

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 "";

    }
}

不要忘记在manifest.xml中授予读写权限

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

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:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.parsaniahardik.signaturedemo.MainActivity">

    <com.kyanogen.signatureview.SignatureView
        xmlns:sign="http://schemas.android.com/apk/res-auto"
        android:id="@+id/signature_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        sign:penSize="5dp"
        sign:backgroundColor="#ffffff"
        sign:penColor="#000000"
        sign:enableSignature="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/clear"
        android:text="clear"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/save"
        android:text="save"/>
</LinearLayout>

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

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
埋情葬爱 2024-12-03 14:15:56

许多应用程序要求其用户接受协议,但我想不出我使用过的哪个应用程序要求我提供实际签名。

您的用户无法以通常的方式接受您的协议是否有充分的理由? (通过复选框或点击标有“我接受”的按钮?)

  • 为什么需要用户签名的图形表示?
  • 用手指写字很难,用手指写字更难。
    在智能手机屏幕上书写(用手指)。

还存在与获取用户签名的图形表示相关的隐私问题。一旦获得,我不知道贵公司将如何处理我的签名。签名是宝贵的个人信息,最终可能被用于身份盗窃。

Many applications ask their users to accept an agreement, but I can't think of one I've used that's asked me for my actual signature.

Is there a good reason that your users aren't able to accept yr agreement in the usual way? (via a check box or by hitting a button marked 'I accept'?)

  • Why is a graphical representation of the users signature required?
  • It's difficult to write using a finger, and it's even more difficult to
    write (using a finger) on a smart phone screen.

There are also privacy concerns relating to obtaining a graphical representation of a user's signature. Once obtained, I have no idea what your company will do with my signature. A signature is a valuable piece of personal information, which could ultimately be used for identity theft.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文