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();//主界面回调后隐藏提示文字

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值