0

我想在我的应用程序中有一个功能,用户可以在其中绘制他们的签名并可以保存为图像。我正在考虑将任何签名应用程序集成到我的应用程序中。可能吗?如果不是,请提供解决方案。谢谢。

4

2 回答 2

0

查看 Android SDK 安装中的示例文件夹。有一个名为 FingerPaint.java 的类,您可以根据自己的目的进行调整。保存签名时,只需调用 view.getDrawingCache() 即可获取位图。

于 2013-07-29T19:40:32.180 回答
0

使用手势叠加视图的签名板代码

GestureOverlayView gestureView;
String path;
File file;
Bitmap bitmap;
public boolean gestureTouch=false;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gesture_signature);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Button donebutton=(Button)findViewById(R.id.DoneButton);
    donebutton.setText("Done");
    Button clearButton=(Button)findViewById(R.id.ClearButton);
    clearButton.setText("Clear");

    path=Environment.getExternalStorageDirectory().toString();//+"/signature.png";
    File directory = new File(path, "testSign");
    directory.mkdir();
    file = new File(directory,"signature.png");
    file.delete();

    gestureView=(GestureOverlayView)findViewById(R.id.signaturePad);
    gestureView.setDrawingCacheEnabled(true);

    gestureView.setAlwaysDrawnWithCacheEnabled(true);
    gestureView.setHapticFeedbackEnabled(false);
    gestureView.cancelLongPress();
    gestureView.cancelClearAnimation();

   gestureView.addOnGestureListener(new GestureOverlayView.OnGestureListener() {
       @Override
       public void onGestureStarted(GestureOverlayView arg0, MotionEvent arg1) {
           if (arg1.getAction() == MotionEvent.ACTION_MOVE) {
               gestureTouch = false;
           } else {
               gestureTouch = true;
           }
       }

       @Override
       public void onGesture(GestureOverlayView overlay, MotionEvent event) {

       }

       @Override
       public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {

       }

       @Override
       public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {

       }
   });

    donebutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                bitmap = Bitmap.createBitmap(gestureView.getDrawingCache());
                file.createNewFile();
                FileOutputStream fos = new FileOutputStream(file);
                fos = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (gestureTouch == false) {
                setResult(0);
                finish();
            } else {
                setResult(1);
                finish();
            }
        }
    });

    clearButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            gestureView.invalidate();
            gestureView.clear(true);
            gestureView.clearAnimation();
            gestureView.cancelClearAnimation();
        }
    });
}
于 2016-06-13T06:29:25.810 回答