android 电子签名 手写签名 功能实现,字节跳动技术总监自爆

本文详细介绍了在Android平台上实现电子签名和手写签名功能的步骤,包括使用Canvas、Bitmap进行绘制,调整签名图像大小以适应不同屏幕,并提供了获取透明背景签名图片的方法。
摘要由CSDN通过智能技术生成

return false;

}

// invalidate();

invalidate((int) (mDirtyRect.left - mMaxWidth), (int) (mDirtyRect.top - mMaxWidth),

(int) (mDirtyRect.right + mMaxWidth), (int) (mDirtyRect.bottom + mMaxWidth));

return true;

}

@Override

protected void onDraw(Canvas canvas) {

if (mSignatureBitmap != null) {

canvas.drawBitmap(mSignatureBitmap, 0, 0, mPaint);

}

}

public void setOnSignedListener(OnSignedListener listener) {

mOnSignedListener = listener;

}

public boolean isEmpty() {

return mIsEmpty;

}

public Bitmap getSignatureBitmap() {

Bitmap originalBitmap = getTransparentSignatureBitmap();

Bitmap whiteBgBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(),

Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(whiteBgBitmap);

canvas.drawColor(Color.WHITE);

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

return whiteBgBitmap;

}

public void setSignatureBitmap(Bitmap signature) {

clear();

ensureSignatureBitmap();

RectF tempSrc = new RectF();

RectF tempDst = new RectF();

int dWidth = signature.getWidth();

int dHeight = signature.getHeight();

int vWidth = getWidth();

int vHeight = getHeight();

// Generate the required transform.

tempSrc.set(0, 0, dWidth, dHeight);

tempDst.set(0, 0, vWidth, vHeight);

Matrix drawMatrix = new Matrix();

drawMatrix.setRectToRect(tempSrc, tempDst, Matrix.ScaleToFit.CENTER);

Canvas canvas = new Canvas(mSignatureBitmap);

canvas.drawBitmap(signature, drawMatrix, null);

setIsEmpty(false);

invalidate();

}

public Bitmap getTransparentSignatureBitmap() {

ensureSignatureBitmap();

return mSignatureBitmap;

}

public Bitmap getTransparentSignatureBitmap(boolean trimBlankSpace) {

if (!trimBlankSpace) {

return getTransparentSignatureBitmap();

}

ensureSignatureBitmap();

int imgHeight = mSignatureBitmap.getHeight();

int imgWidth = mSignatureBit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值