我正在开发Android项目,我正在使用View类在画布上绘制空白圆圈。 这是我的代码:
Paint paint=new Paint();
paint.setAntiAlias(true); // enable anti aliasing
paint.setColor(Color.BLUE); // set default color to light green
paint.setDither(true); // enable dithering
paint.setStyle(Paint.Style.STROKE); // set to STOKE
paint.setStrokeWidth(1);
paint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want
paint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too
canvas.drawCircle(x, y, 50, paint);
但是结果圈有一些锯齿,我怎么能画出没有任何锯齿的圆圈?
答案 0 :(得分:2)
我已尝试使用以下显示的代码在画布中绘制圆圈:
public class MainActivity extends ActionBarActivity {
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.imv_Image);
createBitMap();
}
private void createBitMap() {
Bitmap bitMap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); // creates
// bmp
bitMap = bitMap.copy(bitMap.getConfig(), true); // lets bmp to be
// mutable
Canvas canvas = new Canvas(bitMap); // draw a canvas in defined bmp
Paint paint = new Paint();
// smooths
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4.5f);
// opacity
// p.setAlpha(0x80); //
canvas.drawCircle(50, 50, 30, paint);
image.setImageBitmap(bitMap);
}
}
答案 1 :(得分:0)
尝试设置Paint抗锯齿标志:
paint.setFlags(Paint.ANTI_ALIAS_FLAG)
请参阅:http://developer.android.com/reference/android/graphics/Paint.html#ANTI_ALIAS_FLAG
如果这不起作用,圆圈可能是抗锯齿的,但屏幕密度太低而无法注意。