Android 特别好用的框架 五,手写电子签名保存图片

今天分享一个手写签名特别好用的框架

第一步,添加依赖

implementation 'com.github.gcacace:signature-pad:1.3.1'

第二步,添加布局

<?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"
        android:background="@color/white">

    <com.github.gcacace.signaturepad.views.SignaturePad
            android:id="@+id/pad"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="@drawable/edt_shape"
            android:layout_margin="20dp"/>
    <LinearLayout android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:orientation="horizontal">
        <Button
                android:id="@+id/bt_clear"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:text="清除"
                android:textColor="@color/white"
                android:background="@color/xian"
                android:textSize="16sp"/>
        <Button
                android:id="@+id/bt_save"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_marginLeft="20dp"
                android:layout_height="match_parent"
                android:text="保存"
                android:textColor="@color/white"
                android:background="@color/blue"
                android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>

第三步,使用

   bt_save.setOnClickListener {
            if (pad.isEmpty) {
                ToastUtils.showShort("请签名")
                return@setOnClickListener
            }

          pad.signatureBitmap//即为签名图片
        }
        bt_clear.setOnClickListener {
            pad.clear()

        }
注:这个框架封装的很实用,我们使用起来也很方便快捷,可以直接获取Bitmap图片,也可以直接清除当前写过的,大家有好的框架记得一起分享下噢
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
android电子签名,屏幕上手写签名 搜集很多资料,项目能够完美运行,拿来即可使用,整理备用 应用场景: 就是在屏幕是用手写字,然后保存成图片,简称就是电子签名,可以用在手机上签合同,等技术。 使用技术: 使用了接口回调,绘制完成之后给用户去操作 自定义Dialog,在dialog上画图,给dialog设置主题,dialog的宽高设置为手机屏幕的宽高充满全屏 注意在计算高度的时候记得减去通知栏的高度 注意把画布的背景设置为白色,不然点击缩略图查看的时候是全黑色 参考如下资料: http://hbxflihua.iteye.com/blog/1512765 http://www.jianshu.com/p/c4f017603413 https://github.com/gcacace/android-signaturepad http://download.csdn.net/download/mmlinux/7687091 1,android 如何让自定义dialog的宽度跟屏幕的宽度一样? 在你dialog.show();后面加上 WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.width = (int)(display.getWidth()); //设置宽度 dialog.getWindow().setAttributes(lp); 2,如何获取通知栏的高度? public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimensionPixelSize(resourceId); } return result; } 3,如何对图片进行压缩? http://blog.sina.com.cn/s/blog_497f718e0100sl13.html http://www.cnblogs.com/Soprano/articles/2577152.html
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值