圆形裁剪图片的代码我该怎么加啊????有代码~!



所有方法如上面三个图,圆形裁剪的代码如下:
public Bitmap toRoundBitmap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float roundPx;
float left,top,right,bottom,dst_left,dst_top,dst_right,dst_bottom;
if (width <= height) {
roundPx = width / 2;
top = 0;
bottom = width;
left = 0;
right = width;
height = width;
dst_left = 0;
dst_top = 0;
dst_right = width;
dst_bottom = width; } else {
roundPx = height / 2;
float clip = (width - height) / 2;
left = clip;
right = width - clip;
top = 0;
bottom = height;
width = height;
dst_left = 0;
dst_top = 0;
dst_right = height;
dst_bottom = height; }
Bitmap output = Bitmap.createBitmap(width,
height, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect src = new Rect((int)left, (int)top, (int)right, (int)bottom);
final Rect dst = new Rect((int)dst_left, (int)dst_top, (int)dst_right, (int)dst_bottom); final RectF rectF = new RectF(dst);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, src, dst, paint);
return output;
}
代码应该不需要多写多少, 关键我是搞不太清楚“逻辑”的关系,,
大神么给破一下~!!
...全文
相关推荐
Android裁剪图片为圆形图片Demo
Android裁剪图片为圆形图片Demo
iOS图片选取及圆形裁剪功能实现
在iOS开发中,图片的选取和裁剪是一项基础而又重要的功能,它广泛应用于社交媒体应用、图像编辑器以及用户个人资料编辑等场景中。该功能不仅需要提供友好的用户交互体验,还需兼顾性能优化和系统资源的合理使用。简而言之,图片选取裁剪模块通常涉及以下几个方面:展示图片选择器、从相册中选取图片、对选取的图片进行裁剪,以及最终呈现裁剪后的图片。
iOS 把图片裁剪成圆形
原图: 圆形图片裁剪效果:裁剪成带边框的圆形图片:核心代码:#import <UIKit/UIKit.h>@interface UIImage (image)/** * 生成一张圆形图片 * * @param image 要裁剪的图片 * * @return 生成的圆形图片 */+ (UIImage *)imageWithClipImage:(UIImage *)im
android圆形图片裁剪demo以及实现
android圆形图片裁剪demo以及实现,在处理一些用户头像上传和设置的时候极有可能会用到
C# OpenCVCsharp 图片内圆形识别并裁剪 ,源码
使用C#调用OpenCVCsharp.dll 实现自动识别图片内的圆形,并按照比例在picturebox上画框,双击按照比例无损裁剪



