joshkendrick
joshkendrick

Reputation: 3537

Android canvas.drawPoint ignores Paint.Cap round

I've been working on this for a while. This code:

Log.i(TAG, "stroke style: " + paint.getStyle());
Log.i(TAG, "stroke cap: " + paint.getStrokeCap());
canvas.drawPoint(p.x, p.y, paint);

prints 'STROKE' and 'ROUND' to the logs, but draws a black SQUARE to the map! Anyone know what I need to be doing differently to produce a dot instead of a square!?

Thanks!

EDIT I'm going to give the below suggestion(s) of using drawCircle a shot, but I was just confused I guess because everything I've read indicates you should be able to indicate you want a circle that way. One example being this google book entry

Upvotes: 0

Views: 2269

Answers (3)

Logan Pickup
Logan Pickup

Reputation: 2374

It draws correctly if you draw to a canvas backed by a bitmap. It doesn't seem to draw correctly if you draw directly to the screen (i.e. a canvas passed to a View's onDraw() method). Another way of getting around the problem is, therefore, to first render to a bitmap and then draw that to the screen.

Upvotes: 0

Pavel Dudka
Pavel Dudka

Reputation: 20934

Try to use drawCircle instead

circlePaint.setStyle(Style.FILL);
circlePaint.setAntiAlias(true);
circlePaint.setColor(0xFFFF0000); //opaque red
float radius = 10f; //10 pixels

canvas.drawCircle(p.x, p,y, radius, circlePaint);

Upvotes: 1

Praful Bhatnagar
Praful Bhatnagar

Reputation: 7435

you can try drawCircle() with p.x and p.y as center (first and second argument) and use 1 or 2 as radius depend on how big you want the dot to be and use the paint with stroke style FILL..

Upvotes: 0

Related Questions