Given two points on an emulator (x and y values for both coordinates), how do I draw a line connecting them?
I have already retrieved the two coordinates like this...
//imports not included
ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(iv.getLayoutParams());
float fx = event.getX();
float fy = event.getY();
int x = (int)fx;
int y = (int)fy;
Use Canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
method to draw a straight line between two points using X, Y coordinates like the following Code Snippet.
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setStrokeWidth(5);
paint.setColor(Color.Black);
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
Canvas.drawLine(startX, startY, stopX, stopY, paint);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.