gpt4 book ai didi

objective-c - 如何在 iOS 上删除 UIImageView 图像的某些部分?

转载 作者:行者123 更新时间:2023-12-05 09:00:20 26 4
gpt4 key购买 nike

我有一个带有 UIImageView 的 View 和一个图像集。我想像在 Photoshop 中用橡皮擦一样删除图像。我如何实现这一目标?另外,如何撤消删除?

最佳答案

如果知道要删除的区域,可以创建一个相同大小的新图像,将蒙版设置为完整图像减去要删除的区域,将完整图像绘制到新图像中,然后使用那作为新形象。要撤消,只需使用之前的图像即可。

编辑

示例代码。假设您要从 ImageView imgView 中删除的区域由 erasePath 指定:

- (void) clipImage 
{
UIImage *img = imgView.image;
CGSize s = img.size;
UIGraphicsBeginImageContext(s);
CGContextRef g = UIGraphicsGetCurrentContext();
CGContextAddPath(g,erasePath);
CGContextAddRect(g,CGRectMake(0,0,s.width,s.height));
CGContextEOClip(g);
[img drawAtPoint:CGPointZero];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

关于objective-c - 如何在 iOS 上删除 UIImageView 图像的某些部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1487601/

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