实现在android上画图的项目

时间:2018-04-20 02:53:15
【文件属性】:

文件名称:实现在android上画图的项目

文件大小:1.06MB

文件格式:RAR

更新时间:2018-04-20 02:53:15

画图

private float refX; //手指移动时上一刻在X轴上的位置 private float refY; //Y private float initialX; //触摸屏幕时,按下去时的X轴上位置 private float initialY; //Y private float centerX; //画圆时圆心点X轴位置 private float centerY; //Y轴位置 private float circleRadius = 1; //半径 aaaaaa private RectF ovalRect; //用于画椭圆时的矩形类 private Point point; //用于画点的“点”类 private Rect rect; //用于画正方形/矩形的矩形类 private Point[] trianglePoints = new Point[3]; //用于画三角形时存储三角形的三个点 private Point[] points = new Point[3]; private Paint paint; //画笔 private Path path; //图像路径 private Bitmap mBitmap; //用来实现双缓冲的Bitmap private Canvas mCanvas; //用来实现双缓冲的Canvas private DisplayMetrics dm; private int drawType = DrawType.Scrawl; //画图类型 private boolean isClear = false; //onDraw方法中用来判断当前是否是清除图像 public DrawView(Context context, AttributeSet attrs) { super(context, attrs); createCanvas(); //设置画笔属性 paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.RED); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setStrokeCap(Paint.Cap.ROUND); //设置笔刷圆形样式 paint.setPathEffect(new CornerPathEffect(20)); //实例“路径”对象 path = new Path(); } @Override public boolean onTouchEvent(MotionEvent event) { float currentX = event.getX(); float currentY = event.getY(); //如果是随意涂鸦 if(drawType == DrawType.Scrawl){ switch(event.getAction()){ case MotionEvent.ACTION_DOWN: //手按下屏幕的时候 paint.setPathEffect(new CornerPathEffect(20)); //设置圆滑效果 path.moveTo(currentX, currentY); //将画笔移动到此,设置路径的第一个点 refX = currentX; refY = currentY; break; case MotionEvent.ACTION_MOVE: //手指在屏幕上移动的时候 path.lineTo(currentX, currentY); //为路径添加一个点 refX = currentX; refY = currentY; break; case MotionEvent.ACTION_UP: //手指提起来的时候 mCanvas.drawPath(path, paint); paint.setPathEffect(new CornerPathEffect(0)); //画完后取消圆滑效果,否则在画矩形等图形的时候边角也会是圆角 path.reset(); //清空Path的任何直线和曲线,让它变成空,以便下次使用 break; } invalidate(); //这个方法请求View进行重绘,所以会调用onDraw方法


【文件预览】:
DrawProject
----.project(847B)
----project.properties(563B)
----src()
--------com()
----AndroidManifest.xml(881B)
----res()
--------drawable-ldpi()
--------drawable-hdpi()
--------values-v11()
--------menu()
--------drawable-mdpi()
--------layout()
--------values-sw600dp()
--------drawable-xxhdpi()
--------drawable-xhdpi()
--------values()
--------values-sw720dp-land()
--------values-v14()
----.settings()
--------org.eclipse.jdt.core.prefs(208B)
----assets()
----gen()
--------com()
----libs()
--------android-support-v4.jar(384KB)
----.classpath(364B)
----proguard-project.txt(781B)
----ic_launcher-web.png(50KB)
----bin()
--------resources.ap_(64KB)
--------DrawProject.apk(218KB)
--------classes()
--------AndroidManifest.xml(881B)
--------dexedLibs()
--------jarlist.cache(119B)
--------res()
--------classes.dex(448KB)

网友评论