79-图片擦除(纯代码)
来源:互联网 发布:电影票电子码软件 编辑:程序博客网 时间:2024/04/29 06:15
// ViewController.m
// 图片擦除(纯代码)
// 如果想要要通过storyboard拖拽方式操作,拖两个imageview
// 其中用于做擦除操作的要连线,并给其拖一个手指移动的手势
#import "ViewController.h"
@interface ViewController ()
//保存用于做擦除操作的图片
@property (nonatomic,weak) UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建两个imageview
//用于显示擦除后的图片
UIImageView *imageView1=[[UIImageView alloc] init];
imageView1.image=[UIImage imageNamed:@"2B"];
//设置ImageView可以和用户交互
imageView1.userInteractionEnabled=NO;
imageView1.frame=self.view.bounds;
[self.view addSubview:imageView1];
//用于做擦除操作的图片
UIImageView *imageView2=[[UIImageView alloc] init];
imageView2.image=[UIImage imageNamed:@"2A"];
imageView2.frame=self.view.bounds;
imageView2.userInteractionEnabled=YES;
_imageView=imageView2;
[self.view addSubview:imageView2];
//2.给用于做擦除操作的imageView添加手指移动手势
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[_imageView addGestureRecognizer:pan];
}
//3.监听手指移动事件
-(void) pan:(UIPanGestureRecognizer *)pan
{
//获取当前手指位置
CGPoint curP=[pan locationInView:_imageView];
//开启位图上下文
UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size,NO, 0);
//绘制图片
[_imageView.image drawInRect:_imageView.bounds];
//获取当前上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//擦除范围大小
CGFloat wh=20;
CGRect clearRect= CGRectMake(curP.x, curP.y, wh, wh);
//擦除图片
CGContextClearRect(ctx, clearRect);
//生成新的图片
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
//给imageView赋值
_imageView.image=image;
}
@end
#import "ViewController.h"
@interface ViewController ()
//保存用于做擦除操作的图片
@property (nonatomic,weak) UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建两个imageview
//用于显示擦除后的图片
UIImageView *imageView1=[[UIImageView alloc] init];
imageView1.image=[UIImage imageNamed:@"2B"];
//设置ImageView可以和用户交互
imageView1.userInteractionEnabled=NO;
imageView1.frame=self.view.bounds;
[self.view addSubview:imageView1];
//用于做擦除操作的图片
UIImageView *imageView2=[[UIImageView alloc] init];
imageView2.image=[UIImage imageNamed:@"2A"];
imageView2.frame=self.view.bounds;
imageView2.userInteractionEnabled=YES;
_imageView=imageView2;
[self.view addSubview:imageView2];
//2.给用于做擦除操作的imageView添加手指移动手势
UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[_imageView addGestureRecognizer:pan];
}
//3.监听手指移动事件
-(void) pan:(UIPanGestureRecognizer *)pan
{
//获取当前手指位置
CGPoint curP=[pan locationInView:_imageView];
//开启位图上下文
UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size,NO, 0);
//绘制图片
[_imageView.image drawInRect:_imageView.bounds];
//获取当前上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//擦除范围大小
CGFloat wh=20;
CGRect clearRect= CGRectMake(curP.x, curP.y, wh, wh);
//擦除图片
CGContextClearRect(ctx, clearRect);
//生成新的图片
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
//给imageView赋值
_imageView.image=image;
}
@end
0 0
- 79-图片擦除(纯代码)
- 图片擦除
- 纯Java代码 图片压缩
- 纯代码实现图片预览
- 图片擦除-美女效果
- Quartz2D - 图片擦除
- XMG Quartz2D 图片擦除
- iOS 图片擦除
- 【图片擦除】jQuery.eraser图像擦除插件
- c++擦除mbr代码
- 纯代码方式的图片透明传输
- 用纯ASP代码实现图片上传
- 纯CSS代码实现图片轮显
- 用纯ASP代码实现图片上传
- 纯js图片切换幻灯片代码
- 纯java代码 改变图片的大小
- 纯代码无图片Tips实现过程
- 图片适配 压缩比例 (纯代码)
- c++ 冒泡排序改进
- 79-图片裁剪(自定义区域大小)
- 防止头文件重复包含
- 为来的路该如何走!
- c++的new和delete
- 79-图片擦除(纯代码)
- uva 11300 Spreading the Wealth (中位数的应用)
- java static block
- 如何在django中使用多个数据库
- Android Studio教程一----下载与安装
- 笔记本无线连接时(无本地连接) 与本地虚拟机相互ping通
- kafka consumer group总结
- dmesg-定位I/O问题
- C++之RAII技术解析