gpt4 book ai didi

android - 将边框设置为圆形图像问题

转载 作者:行者123 更新时间:2023-11-29 21:04:55 25 4
gpt4 key购买 nike

我找到了几个关于如何创建带圆圈的图像的示例,并采用了最简单的一个。我正在尝试在圆形图像上创建一个黑色边框,但我认为我看不到它。如何为新的圆形图像绘制黑色边框。

这是我的代码:

  public Bitmap getCircleBitmap(Bitmap bitmap){
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setShader(shader);
paint.setAntiAlias(true);
Canvas c = new Canvas(circleBitmap);

Path path = new Path();

path.addCircle(((float) bitmap.getWidth()) / 2,((float) bitmap.getHeight()) / 2 ,
(Math.min(((float) bitmap.getWidth()),((float) bitmap.getHeight())) / 2),Path.Direction.CCW);
c.clipPath(path);
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2 , bitmap.getWidth()/2, paint);
return circleBitmap;
}

谢谢。

最佳答案

希望对你有帮助,这对我有用..

int w = bitmap.getWidth();                                          
int h = bitmap.getHeight();

int radius = Math.min(h / 2, w / 2);
Bitmap output = Bitmap.createBitmap(w + 8, h + 8, Config.ARGB_8888);

Paint p = new Paint();
p.setAntiAlias(true);

Canvas c = new Canvas(output);
c.drawARGB(0, 0, 0, 0);
p.setStyle(Style.FILL);

c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);

p.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

c.drawBitmap(bitmap, 4, 4, p);
p.setXfermode(null);
p.setStyle(Style.STROKE);
p.setColor(Color.WHITE);
p.setStrokeWidth(3);
c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);

return output;

关于android - 将边框设置为圆形图像问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24864326/

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