

copy修飾的時候set方法是第一行代碼,偽代碼就是需要做上面那個判斷,如果是strong修飾,直接就是最后面代碼直接賦值








截屏代碼,1.0代表圖片最高質(zhì)量,0是最低質(zhì)量

png沒有壓縮質(zhì)量參數(shù),這個方法默認就是不壓縮了,就是最高質(zhì)量

在c語言當中是不會轉(zhuǎn)換的

第一個參數(shù)size乘以最后面的參數(shù),是生成圖片的大小
- (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的內(nèi)容渲染上下文當中.
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內(nèi)容渲染到上下文當中
CGContextRef ctx = UIGraphicsGetCurrentContext();
[imageV.layer renderInContext:ctx];
//擦除上下文當中某一塊區(qū)域
CGContextClearRect(ctx, rect);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
imageV.image = newImage;
UIGraphicsEndImageContext();
}