sách gpt4 ai đã đi

iOS: UIBezierPath ngược (bezierPathWithOvalInRect)

In lại 作者:行者123 更新时间:2023-11-28 18:04:22 34 4
mua khóa gpt4 Nike

我有一个 jpg 图像,在矩形中有一个圆形物体,我想使圆形物体的环境透明...

Ví dụ

(本例去除红色区域)

借助这个iOS make part of an UIImage transparent和“UIBezierPath bezierPathWithOvalInRect”我取得了一些成功,但这在我的对象周围形成了一条路径,我需要反转它,使路径的外部而不是内部透明..

我不确定我必须在哪里更改我的代码才能获得正确的结果..

Đây là mã của tôi:

//BezierPath
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)];

// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(_imgTemp.image.size);
[_imgTemp.image drawAtPoint:CGPointZero];

// Clip to the bezier path and clear that portion of the image.
CGContextRef ngữ cảnh = UIGraphicsGetCurrentContext();
CGContextAddPath(context,bezierPath.CGPath);
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height));

// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self._imgTemp.image = newImage;

有人解决了吗?

1 Câu trả lời

要仅在黑色圆圈内绘制,您应该将 [_imgTemp.image drawAtPoint:CGPointZero]; Di chuyển đến CGContextClip(context); 之后,然后删除 CGContextClearRect( ... ) 完全调用:

//BezierPath
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)];

// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(_imgTemp.image.size);

// Clip to the bezier path and clear that portion of the image.
CGContextRef ngữ cảnh = UIGraphicsGetCurrentContext();
CGContextAddPath(context,bezierPath.CGPath);
CGContextClip(context);

// Draw here when the context is clipped
[_imgTemp.image drawAtPoint:CGPointZero];

// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self._imgTemp.image = newImage;

关于iOS:逆 UIBezierPath (bezierPathWithOvalInRect),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10042087/

34 4 0
Bài viết được đề xuất: python - VS Code 找不到 pytest 测试
Bài viết được đề xuất: python - 在不同的事件循环中竞速两个任务
Bài viết được đề xuất: python - Numpy 从多维数组中选择由索引矩阵指定的矩阵
Bài viết được đề xuất: javascript - 计算数字在数组中出现的时间
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com