如何在android中裁剪椭圆形或面罩形状的图像?

如何在android中裁剪椭圆形或面罩形状的图像?,第1张

概述我正在做相机应用程序.我有方形捕获和裁剪图像.但我需要椭圆形或人脸形状.它是怎么来的?解决方法:我使用了以下方法并将捕获的位图图像传递给此方法.它会奏效.publicBitmapgetRoundedShape(BitmapscaleBitmapImage){inttargetWidth=125;inttargetHeight

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

解决方法:

我使用了以下方法并将捕获的位图图像传递给此方法.它会奏效.

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

输出如下: –

总结

以上是内存溢出为你收集整理的如何在android中裁剪椭圆形或面罩形状的图像?全部内容,希望文章能够帮你解决如何在android中裁剪椭圆形或面罩形状的图像?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存