gpt4 book ai didi

android - 如何在 android 中以椭圆形或 mask 形状裁剪图像?

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:31 26 4
gpt4 key购买 nike

我正在做相机应用程序。我有方形的捕获和裁剪图像。但我需要椭圆形或人脸形状。怎么来的?

最佳答案

我使用了以下方法并将捕获的位图图像传递给此方法。它会起作用。

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
int targetWidth = 125;
int targetHeight = 125;

Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(
((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CCW);

canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(
sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap
.getHeight()), new Rect(0, 0, targetWidth,
targetHeight), p);
return targetBitmap;
}

输出如下:- Image

关于android - 如何在 android 中以椭圆形或 mask 形状裁剪图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15200214/

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