我正在做相机应用程序.我有方形捕获和裁剪图像.但我需要椭圆形或人脸形状.它是怎么来的?
解决方法:
我使用了以下方法并将捕获的位图图像传递给此方法.它会奏效.
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中裁剪椭圆形或面罩形状的图像?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)