android手写签名背景保存,Android实现手写签名的操作方法

随着移动设备的普及,人们越来越依赖移动设备,这给人们带来了很多便利,其实我们手写签名在一些金融行业得到了广泛的应用,下面就让爱站技术频道小编带大家来了解Android实现手写签名的操作方法吧!

package com.****.*****.widget;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Path;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.view.View;

/**

* This view implements the drawing canvas.

*

* It handles all of the input events and drawing functions.

* 签名版

*/

public class PaintView extends View {

private Paint paint;

private Canvas cacheCanvas;

private Bitmap cachebBitmap;

private Path path;

private OnMoveLisener lisener;

public void setSize(int width,int height,OnMoveLisener lisener) {

this.lisener=lisener;

init(width,height);

}

public PaintView(Context context, AttributeSet attrs) {

super(context, attrs);

//init(0,0);

}

public Bitmap getCachebBitmap() {

return cachebBitmap;

}

private void init(int width,int height) {

paint = new Paint();

paint.setAntiAlias(true);

paint.setStrokeWidth(3);

paint.setStyle(Paint.Style.STROKE);

paint.setColor(Color.BLACK);

path = new Path();

cachebBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

cacheCanvas = new Canvas(cachebBitmap);

cacheCanvas.drawColor(Color.WHITE);

}

public void clear() {

if (cacheCanvas != null) {

paint.setColor(Color.WHITE);

cacheCanvas.drawPaint(paint);

paint.setColor(Color.BLACK);

cacheCanvas.drawColor(Color.WHITE);

invalidate();

}

}

@Override

protected void onDraw(Canvas canvas) {

// canvas.drawColor(BRUSH_COLOR);

canvas.drawBitmap(cachebBitmap, 0, 0, null);

canvas.drawPath(path, paint);

}

@Override

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

int curW = cachebBitmap != null ? cachebBitmap.getWidth() : 0;

int curH = cachebBitmap != null ? cachebBitmap.getHeight() : 0;

if (curW >= w && curH >= h) {

return;

}

if (curW < w)

curW = w;

if (curH < h)

curH = h;

Bitmap newBitmap = Bitmap.createBitmap(curW, curH, Bitmap.Config.ARGB_8888);

Canvas newCanvas = new Canvas();

newCanvas.setBitmap(newBitmap);

if (cachebBitmap != null) {

newCanvas.drawBitmap(cachebBitmap, 0, 0, null);

}

cachebBitmap = newBitmap;

cacheCanvas = newCanvas;

}

private float cur_x, cur_y;

@Override

public boolean onTouchEvent(MotionEvent event) {

getParent().requestDisallowInterceptTouchEvent(true);// 通知父控件勿拦截本控件touch事件

float x = event.getX();

float y = event.getY();

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN: {

cur_x = x;

cur_y = y;

path.moveTo(cur_x, cur_y);

break;

}

case MotionEvent.ACTION_MOVE: {

path.quadTo(cur_x, cur_y, x, y);

cur_x = x;

cur_y = y;

lisener.hideWords();//隐藏提醒的文字

break;

}

case MotionEvent.ACTION_UP: {

cacheCanvas.drawPath(path, paint);

path.reset();

break;

}

}

invalidate();

return true;

}

public interface OnMoveLisener{

void hideWords();//主界面回调后隐藏提示文字

}

}

通过以上的介绍,相信大家已经明了Android实现手写签名的操作方法,不过在操作的时候一定要谨慎,选择有资质的平台学习还是很重要的,更多的知识尽在爱站技术频道网。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值