copy修饰的时候set方法是第一行代码,伪代码就是需要做上面那个判断,如果是strong修饰,直接就是最后面代码直接赋值
截屏代码,1.0代表图片最高质量,0是最低质量
png没有压缩质量参数,这个方法默认就是不压缩了,就是最高质量
在c语言当中是不会转换的
第一个参数size乘以最后面的参数,是生成图片的大小
- (IBAction)pan:(UIPanGestureRecognizer *)pan {
CGPoint curP = [pan locationInView:self.imageView];
//获取起始点
if (pan.state == UIGestureRecognizerStateBegan) {
//获取当前点
self.startP = curP;
} else if (pan.state == UIGestureRecognizerStateChanged) {
//获取当前点
CGFloat X = self.startP.x;
CGFloat Y = self.startP.y;
CGFloat W = curP.x - self.startP.x;
CGFloat H = curP.y - self.startP.y;
CGRect rect = CGRectMake(X, Y, W, H);
self.coverVeiw.frame = rect;
} else if(pan.state == UIGestureRecognizerStateEnded){
//开启一个位图上下文
UIGraphicsBeginImageContextWithOptions(self.imageView.bounds.size, NO, 0.0);
//UIRectClip(self.coverVeiw.frame);
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.coverVeiw.frame];
[path addClip];
//把ImageView的内容渲染上下文当中.
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.imageView.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageView.image = newImage;
UIGraphicsEndImageContext();
[self.coverVeiw removeFromSuperview];
}
}
// 图片擦除
- (IBAction)pan:(UIPanGestureRecognizer *)pan {
//获取当前手指的点
UIImageView *imageV = (UIImageView *)pan.view;
CGPoint curP = [pan locationInView:imageV];
CGRect rect = CGRectMake(curP.x - 15, curP.y - 15, 30, 30);
//开启一个位图上下文
UIGraphicsBeginImageContextWithOptions(imageV.bounds.size, NO, 0.0);
//把ImageView内容渲染到上下文当中
CGContextRef ctx = UIGraphicsGetCurrentContext();
[imageV.layer renderInContext:ctx];
//擦除上下文当中某一块区域
CGContextClearRect(ctx, rect);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
imageV.image = newImage;
UIGraphicsEndImageContext();
}
网友评论