本文实例为大家分享了android实现签名涂鸦手写板的具体代码,供大家参考,具体内容如下
布局文件
//开始签名
private void startsignature() { // 获取屏幕尺寸 displaymetrics mdisplaymetrics = new displaymetrics(); getwindow().getwindowmanager().getdefaultdisplay().getmetrics(mdisplaymetrics); } @override public void onwindowfocuschanged(boolean hasfocus) { super.onwindowfocuschanged(hasfocus); if(hasfocus&&mpaintview==null){ int screenwidth = mfl_signature.getmeasuredwidth(); int screenheight = mfl_signature.getmeasuredheight(); mpaintview=new paintview(getapplicationcontext(),screenwidth, screenheight); mfl_signature.addview(mpaintview); mpaintview.requestfocus(); } }
//创建签名文件
private void createsignfile() { fileoutputstream fos = null; file file = null; try { path= generateimgepath(); file = new file(path); fos = new fileoutputstream(file); //如果设置成 mpaintbitmap.compress(bitmap.compressformat.jpeg, 100, fos); } catch (ioexception e) { e.printstacktrace(); } finally { try { if (fos != null) { fos.close(); } } catch (ioexception e) { e.printstacktrace(); } } }
//重新签名
if (mpaintview.getpath().isempty()){ toastutils.showshort(this,"您还没有签名呦"); }else { mpaintview.clear(); }