将图片写入相册的方法代码

//保存到相册

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;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容