android手写签名的demo网上其实有很多,但是大多没考虑到签名用在哪里的问题,所以就需要背景图设置,保存电子签名的时候 会连同背景图一起保存 这才达到了电子签名的效果,背景可以放置合同,请假条,设计批文等等。下面是效果图:
如果单独设置背景图,签名view.setBackground,保存签名的时候,只会保存屏幕最顶不得view,所以背景图是保存不下来的,既然签名是画布画出来的,我们就可以在画布上设置背景图
private int width, height; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); } public void ensureSignatureBitmap() { if (mSignatureBitmap == null) { mSignatureBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); mSignatureBitmapCanvas = new Canvas(mSignatureBitmap); mSignatureBitmapCanvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.a), new Rect(0, 0, BitmapFactory.decodeResource(getResources(), R.drawable.a).getWidth(), BitmapFactory.decodeResource(getResources(), R.drawable.a).getHeight()), new Rect(0, 0, width, height), mPaint); } }
这样就可以签名结束后 签名连同背景一同保存到相册里面了
附上demo链接。如果你有更好的办法,欢迎大家一起交流