gpt4 book ai didi

android - 在没有锯齿的情况下在Android中绘制圆圈

转载 作者:行者123 更新时间:2023-11-29 21:03:22 26 4
gpt4 key购买 nike

我正在开发 Android 项目,我正在使用 View 类在 Canvas 上绘制空圆。这是我的代码:

    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);

但是结果圆有一些锯齿,我怎样才能画出没有任何锯齿的圆?

最佳答案

我已经尝试了下面显示的在 Canvas 中绘制圆圈的代码:

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);
}
}

关于android - 在没有锯齿的情况下在Android中绘制圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25306981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com