Android实现签名涂鸦手写板

作者:BoomLei 时间:2022-07-27 04:10:14 

本文实例为大家分享了Android实现签名涂鸦手写板的具体代码,供大家参考,具体内容如下

布局文件


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

<FrameLayout
   android:id="@+id/fl_signature"
   android:layout_width="fill_parent"
   android:layout_height="200dp"
   android:layout_marginLeft="20dp"
   android:layout_marginRight="20dp"
   android:layout_marginTop="10dp"
   android:background="@drawable/singature_bg"
   android:gravity="top">
 </FrameLayout>
 <ImageView
   android:id="@+id/iv_signature"
   android:layout_width="fill_parent"
   android:layout_height="200dp"
   android:layout_marginLeft="20dp"
   android:layout_marginRight="20dp"
   android:layout_marginTop="10dp"
   android:background="@drawable/signature_shape"
   android:gravity="top"
   android:visibility="gone"/>

<RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="20dp"
       android:layout_marginBottom="20dp">

<TextView
         android:id="@+id/tv_revert_signature"
         android:layout_width="100dp"
         android:layout_height="35dp"
         android:layout_alignParentRight="true"
         android:layout_marginRight="140dp"
         android:background="@drawable/btn_order_details_pay_bg"
         android:gravity="center"
         android:paddingLeft="30dp"
         android:paddingRight="30dp"
         android:text="重签"
         android:textColor="@color/code_number_bg"
         android:textSize="@dimen/text_title_word" />

<TextView
         android:id="@+id/tv_signature_save"
         android:layout_width="100dp"
         android:layout_height="35dp"
         android:layout_alignParentRight="true"
         android:layout_marginRight="20dp"
         android:background="@drawable/bt_bg"
         android:gravity="center"
         android:paddingLeft="30dp"
         android:paddingRight="30dp"
         android:text="保存"
         android:textColor="@color/white"
         android:textSize="@dimen/text_title_word" />

</RelativeLayout>

</LinearLayout>

Android实现签名涂鸦手写板

//开始签名


private void StartSignature() {
   // 获取屏幕尺寸
   DisplayMetrics mDisplayMetrics = new DisplayMetrics();
   getWindow().getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
 }

@Override
 public void onWindowFocusChanged(boolean hasFocus) {
   super.onWindowFocusChanged(hasFocus);
   if(hasFocus&&mPaintView==null){
     int screenWidth = mFl_signature.getMeasuredWidth();
     int screenHeight = mFl_signature.getMeasuredHeight();
     mPaintView=new PaintView(getApplicationContext(),screenWidth, screenHeight);
     mFl_signature.addView(mPaintView);
     mPaintView.requestFocus();
   }
 }

//创建签名文件


private void createSignFile() {

FileOutputStream fos = null;

File file = null;
   try {
     path= generateImgePath();
     file = new File(path);
     fos = new FileOutputStream(file);

//如果设置成
     mPaintBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       if (fos != null) {
         fos.close();
       }

} catch (IOException e) {
       e.printStackTrace();
     }
   }
 }

//重新签名


if (mPaintView.getPath().isEmpty()){
         ToastUtils.showShort(this,"您还没有签名呦");
       }else {
         mPaintView.clear();

}

来源:https://blog.csdn.net/BoomLei/article/details/77368473

标签:Android,签名,手写板
0
投稿

猜你喜欢

  • Java利用反射对list对象做过滤

    2023-12-23 07:39:17
  • 解决Java中OutOfMemoryError的问题

    2023-01-26 13:51:03
  • java 制作验证码并进行验证实例详解

    2023-03-18 11:27:56
  • JAVA+Struts2获取服务器地址的方法

    2022-01-26 22:25:11
  • 用JAVA实现单链表,检测字符串是否是回文串

    2021-07-20 07:07:45
  • android中Glide实现加载图片保存至本地并加载回调监听

    2021-12-05 23:00:03
  • 实例详解C#正则表达式

    2023-06-23 00:03:03
  • SpringCloud-Alibaba-Nacos启动失败解决方案

    2023-12-19 05:34:45
  • 浅谈C#与Java两种语言的比较

    2023-09-26 13:05:19
  • 举例讲解设计模式中的访问者模式在Java编程中的运用

    2022-04-04 08:00:45
  • java 垃圾回收机制以及经典垃圾回收器详解

    2022-07-06 05:16:08
  • 如何使用JaCoCo分析java单元测试覆盖率

    2023-01-13 11:38:39
  • C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的方法

    2023-03-26 14:44:41
  • SpringBoot集成kaptcha验证码

    2023-06-26 03:56:17
  • Spring Security基于散列加密方案实现自动登录功能

    2022-09-19 01:10:22
  • java多线程编程之慎重使用volatile关键字

    2022-09-08 00:36:41
  • Java String的intern用法解析

    2023-04-22 19:03:35
  • Kotlin中协程的创建过程详析

    2023-11-27 07:45:16
  • c# 网址压缩简单实现短网址

    2022-10-06 15:37:17
  • Android编程创建桌面快捷方式的常用方法小结【2种方法】

    2023-12-07 00:50:35
  • asp之家 软件编程 m.aspxhome.com