//保存到相册
UIGraphicsBeginImageContext(self.captureImv.bounds.size);
[self.captureImv.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(temp, nil, nil, nil);
将图片存储在本地的方法
NSData *imageData = UIImageJPEGRepresentation(self.completeImage, 1);
NSLog(@"截取后图片为:%uldKB",[imageData length]/1000);
//保存到沙盒
[imageData writeToFile:self.imageFilePath atomically:YES];
NSLog(@"图片在这里-->%@",self.imageFilePath);
截取固定区域图片的方法
//截取全屏
UIGraphicsBeginImageContext(CGSizeMake(k_width, k_height));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//截取所需区域
CGRect captureRect = CGRectMake(capture_x,capture_y,capture_width,capture_width);
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, captureRect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
self.captureImv.image = newImage;