android 签字版
来源:互联网 发布:nero mac os 破解版 编辑:程序博客网 时间:2024/04/29 21:39
public class DrawLineLayout extends View { private static final float STROKE_WIDTH = 5f; /** Need to track this so the dirty region can accommodate the stroke. **/ private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2; private Paint paint = new Paint(); private Path path = new Path(); /** * Optimizes painting by invalidating the smallest possible area. */ private float lastTouchX; private float lastTouchY; private final RectF dirtyRect = new RectF(); private Bitmap cachebBitmap; public DrawLineLayout(Context context, AttributeSet attrs) { super(context, attrs); paint.setAntiAlias(true); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeWidth(STROKE_WIDTH); } /** * 用于清空你已经绘制好的图 */ public void clear() { path.reset(); // Repaints the entire view. invalidate();//重新调用绘制 } @Override protected void onDraw(Canvas canvas) { canvas.drawPath(path, paint); }//更加触摸点绘制线 @Override public boolean onTouchEvent(MotionEvent event) { float eventX = event.getX(); float eventY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: path.moveTo(eventX, eventY); lastTouchX = eventX; lastTouchY = eventY; // There is no end point yet, so don't waste cycles invalidating. return true; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: // Start tracking the dirty region. resetDirtyRect(eventX, eventY); // When the hardware tracks events faster than they are delivered, the // event will contain a history of those skipped points. int historySize = event.getHistorySize(); for (int i = 0; i < historySize; i++) { float historicalX = event.getHistoricalX(i); float historicalY = event.getHistoricalY(i); expandDirtyRect(historicalX, historicalY); path.lineTo(historicalX, historicalY); } // After replaying history, connect the line to the touch point. path.lineTo(eventX, eventY); break; default: return false; } // Include half the stroke width to avoid clipping. invalidate( (int) (dirtyRect.left - HALF_STROKE_WIDTH), (int) (dirtyRect.top - HALF_STROKE_WIDTH), (int) (dirtyRect.right + HALF_STROKE_WIDTH), (int) (dirtyRect.bottom + HALF_STROKE_WIDTH)); lastTouchX = eventX; lastTouchY = eventY; return true; } /** * Called when replaying history to ensure the dirty region includes all * points. */ private void expandDirtyRect(float historicalX, float historicalY) { if (historicalX < dirtyRect.left) { dirtyRect.left = historicalX; } else if (historicalX > dirtyRect.right) { dirtyRect.right = historicalX; } if (historicalY < dirtyRect.top) { dirtyRect.top = historicalY; } else if (historicalY > dirtyRect.bottom) { dirtyRect.bottom = historicalY; } } /** * Resets the dirty region when the motion event occurs. */ private void resetDirtyRect(float eventX, float eventY) { // The lastTouchX and lastTouchY were set when the ACTION_DOWN // motion event occurred. dirtyRect.left = Math.min(lastTouchX, eventX); dirtyRect.right = Math.max(lastTouchX, eventX); dirtyRect.top = Math.min(lastTouchY, eventY); dirtyRect.bottom = Math.max(lastTouchY, eventY); } /** * 保存view视图的bitmap信息 * @return bitmap数据 */ public Bitmap getImage() { Bitmap bitmap = Bitmap.createBitmap(1920, 1080, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); /** * 绘制背景 */ Drawable bgDrawable = getBackground(); if (bgDrawable != null) bgDrawable.draw(canvas); else canvas.drawColor(Color.WHITE); draw(canvas);// 绘制view视图的内容 return bitmap; } /** * 将图像保存到文件 * @return 返回false表示保存失败 */ public boolean saveImageToFile(String filePath) { try { File file = new File(filePath); if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); getImage().compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close();// Toast.makeText(getContext(),"wanc",Toast.LENGTH_SHORT).show(); return true; } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } }}
阅读全文
0 0
- android 签字版
- 生成android 签字
- 保护自己的软件----android 签字三种方法
- 【Android】命令行jarsigner签字和解决找不到证书链错误
- 【Android】命令行jarsigner签字和解决找不到证书链错误
- 领导签字
- JAVA与数字签字
- 网上签字系统
- 命令行jarsigner签字
- 数字签字RSA
- 签字礼仪简介
- 《无间道》中的“盲签字”
- 《电子签字示范法》的主要内容
- 关于WebStart工程的签字、发布
- 公钥加密与数据签字
- 需求文档可以不签字吗? 之一
- IOS 画板(签字板)的实现
- jsp页面签字板及保存-jSignature
- array_merge问题
- 我还清楚的记得,在我而立之年,第一次进入了网吧
- linux后台运行和关闭、查看后台任务
- 【SpringMVC】基础知识总结
- 如何把代码上传到github
- android 签字版
- leetcode[Ugly Number]//待整理多种解法
- Android7.0 Settings主菜单添加一条item
- SpringBoot velocity 模板配置绝对路径的资源路径
- Android全套动画使用技巧
- 1299: 排列
- js判断浏览器环境
- 糊糊的前端学习笔记——浏览器对象【Day08】
- ios 实现控件右上角添加小红点