苹果签名

iphoneqm
首页 > 苹果签名 > 正文内容

android 画布实现签名,Android实现屏幕手写签名

admin12个月前 (12-19)苹果签名369

  Android屏幕手写签名的原理就是把手机屏幕当作画板,把用户手指当作画笔,手指在屏幕上在屏幕上划来划去,屏幕就会显示手指的移动轨迹,就像画笔在画板上写字一样。实现手写签名需要结合绘图的路径工具Path,在有按下动作时调用Path对象的moveTo方法,将路径起始点移动到触摸点;在有移动操作时调用Path对象的quadTo方法,将记录本次触摸点与上次触摸点之间的路径;在有移动操作与提起动作时调用Canvas对象的drawPath方法,将本次触摸绘制在画布上。

android 画布实现签名,Android实现屏幕手写签名

  layout/activity_signature.xml界面布局代码如下:

  xmlns:app="://schemas.android/apk/res-auto"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical"

  android:padding="5dp">

  android:layout_width="match_parent"

  android:layout_height="wrap_content">

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:orientation="vertical">

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:orientation="horizontal">

  android:id="@+id/btn_add_signature"

  android:layout_width="0dp"

  android:layout_height="wrap_content"

  android:layout_weight="1"

  android:text="开始签名"

  android:textColor="@color/black"

  android:textSize="17sp" />

  android:id="@+id/btn_reset_signature"

  android:layout_width="0dp"

  android:layout_height="match_parent"

  android:layout_weight="1"

  android:text="重置"

  android:textColor="@color/black"

  android:textSize="17sp" />

  android:id="@+id/btn_revoke_signature"

  android:layout_width="0dp"

  android:layout_height="match_parent"

  android:layout_weight="1"

  android:text="回退"

  android:textColor="@color/black"

  android:textSize="17sp" />

  android:id="@+id/btn_end_signature"

  android:layout_width="0dp"

  android:layout_height="wrap_content"

  android:layout_weight="1"

  android:text="结束签名"

  android:textColor="@color/black"

  android:textSize="17sp" />

  android:id="@+id/view_signature"

  android:layout_width="match_parent"

  android:layout_height="200dp"

  android:background="@color/white"

  app:paint_color="#0000aa"

  app:stroke_width="3" />

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:orientation="horizontal">

  android:id="@+id/btn_save_signature"

  android:layout_width="0dp"

  android:layout_height="wrap_content"

  android:layout_weight="1"

  android:text="保存图片文件"

  android:textColor="@color/black"

  android:textSize="17sp" />

  android:id="@+id/iv_signature_new"

  android:layout_width="match_parent"

  android:layout_height="200dp"

  android:background="@color/white"

  android:scaleType="fitCenter" />

  SignatureActivity.java逻辑代码如下:

  package com.fukaimei.touchevent;

  import android.graphics.Bitmap;

  import android.os.Bundle;

  import android.os.Handler;

  import android.support.v7.app.AppCompatActivity;

  import android.view.View;

  import android.view.View.OnClickListener;

  import android.widget.ImageView;

  import android.widget.Toast;

  import com.fukaimei.touchevent.filedialog.dialog.FileSaveFragment;

  import com.fukaimei.touchevent.util.BitmapUtil;

  import com.fukaimei.touchevent.widget.SignatureView;

  public class SignatureActivity extends AppCompatActivity implements

  OnClickListener, FileSaveFragment.FileSaveCallbacks {

  private SignatureView view_signature;

  private ImageView iv_signature_new;

  private Bitmap mBitmap;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_signature);

  view_signature = (SignatureView) findViewById(R.id.view_signature);

  iv_signature_new = (ImageView) findViewById(R.id.iv_signature_new);

  findViewById(R.id.btn_add_signature).setOnClickListener(this);

  findViewById(R.id.btn_end_signature).setOnClickListener(this);

  findViewById(R.id.btn_reset_signature).setOnClickListener(this);

  findViewById(R.id.btn_revoke_signature).setOnClickListener(this);

  findViewById(R.id.btn_save_signature).setOnClickListener(this);

  }

  @Override

  public void onClick(View v) {

  if (v.getId() == R.id.btn_save_signature) {

  if (mBitmap == null) {

  Toast.makeText(this, "请先开始然后结束签名", Toast.LENGTH_LONG).show();

  return;

  }

  FileSaveFragment.show(this, "jpg");

  } else if (v.getId() == R.id.btn_add_signature) {

  view_signature.setDrawingCacheEnabled(true);

  } else if (v.getId() == R.id.btn_reset_signature) {

  view_signature.clear();

  } else if (v.getId() == R.id.btn_revoke_signature) {

  view_signature.revoke();

  } else if (v.getId() == R.id.btn_end_signature) {

  if (view_signature.isDrawingCacheEnabled() != true) {

  Toast.makeText(this, "请先开始签名", Toast.LENGTH_LONG).show();

  } else {

  mBitmap = view_signature.getDrawingCache();

  iv_signature_new.setImageBitmap(mBitmap);

  mHandler.postDelayed(mResetCache, 100);

  }

  }

  }

  private Handler mHandler = new Handler();

  private Runnable mResetCache = new Runnable() {

  @Override

  public void run() {

  view_signature.setDrawingCacheEnabled(false);

  view_signature.setDrawingCacheEnabled(true);

  }

  };

  @Override

  public boolean onCanSave(String absolutePath, String fileName) {

  return true;

  }

  @Override

  public void onConfirmSave(String absolutePath, String fileName) {

  String path = String.format("%s/%s", absolutePath, fileName);

  BitmapUtil.saveBitmap(path, mBitmap, "jpg", 80);

  Toast.makeText(this, "成功保存图片文件:" + path, Toast.LENGTH_LONG).show();

  }

  }

  Demo程序运行效果界面截图如下:

  以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

  时间: 2019-07-15

扫描二维码推送至手机访问。

版权声明:本文由MDM苹果签名,IPA签名,苹果企业签名,苹果超级签,ios企业签名,iphoneqm.com发布,如需转载请注明出处。

转载请注明出处https://www.iphoneqm.com/iphoneqm/563.html

分享给朋友:

相关文章

苹果app认证证书是什么意思?

苹果app认证证书是什么意思?

  苹果app认证证书是一种用于对苹果应用进行签名和验证的数字证书,它可以证明应用的开发者身份和应用的完整性。   苹果app认证证书分为两种类型:开发证书和分发证书。   开发证书用于在...

苹果ios企业签名多少钱?什么是iOS企业签名,

苹果ios企业签名多少钱?什么是iOS企业签名,

  很多人都在网上搜,什么是iOS企业签名,苹果ios企业签名多少钱?   企业签名由苹果企业级开发者账号(Apple Developer Enterprise Program)导出的证书文件对...

【置顶】2024年宁波市象山县高层次人才项目引进公告

【置顶】2024年宁波市象山县高层次人才项目引进公告

  发布日期:2024-05-09 11:05   信息来源:中共象山县委人才工作领导小组办公室   浏览次数:   为深入贯彻落实党的二十大精神,加快推进象山国家海洋经济发展示范区...

App难上架苹果商店?微导流TF签名官方认可上架方式

App难上架苹果商店?微导流TF签名官方认可上架方式

  3、微导流tf签名链接安装有效期为多长时间?   有效期为3个月,微导流tf签名上架成功后3个月内均可使用。   4、链接下载次数限制为多少?   每个安装链接最多下载10000...

苹果app签名一打开就闪退怎么办?

苹果app签名一打开就闪退怎么办?

  当你打开一个苹果App时,如果它立即闪退,可能是由于多种原因导致的。下面我将详细介绍可能的原因和解决方法。   1. 设备相关问题:检查你的设备是否有充足的存储空间,以及是否有足够的运行内存...

苹果ios企业签名和超级签名是什么?怎么做?有什么区别?

苹果ios企业签名和超级签名是什么?怎么做?有什么区别?

  开发者们在ios软件内测阶段,经常会使用到苹果签名,苹果签名最大的作用就是让软件应用可以不通过App Store和苹果审核,直接在ios苹果手机上安装。其中最常使用的两种苹果签名就是企业签名和超级...

现在,非常期待与您的又一次邂逅

我们努力让每一次邂逅总能超越期待

  • 高效满意
    高效满意

    专业的技术团队

  • 性能稳定
    性能稳定

    响应速度快,放心有保障

  • 用户体验
    用户体验

    响应式布局,兼容各种设备

  • 持续更新
    持续更新

    不断升级维护,更好服务用户