#pragma mark - 截取图片
- (void)cutMapView:(UIView *)theView
{
//************** 得到图片 *******************
CGRect rect = theView.frame; //截取图片大小
//开始取图,参数:截图图片大小
UIGraphicsBeginImageContext(rect.size);
//截图层放入上下文中
[theView.layer renderInContext:UIGraphicsGetCurrentContext()];
//从上下文中获得图片
UIImage *p_w_picpath = UIGraphicsGetImageFromCurrentImageContext();
//结束截图
UIGraphicsEndImageContext();
//************** 存图片 *******************
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu"]]; // 保存文件的名称
NSLog(@"filePath = %@",filePath);
//UIImagePNGRepresentation方法将p_w_picpath对象转为NSData对象
//写入文件中
BOOL result = [UIImagePNGRepresentation(p_w_picpath)writeToFile: filePathatomically:YES];
NSLog(@"result = %d",result);
//*************** 截取小图 ******************
CGRect rect1 = CGRectMake(90, 0, 82, 82);//创建矩形框
//对图片进行截取
UIImage * p_w_picpath2 = [UIImagep_w_picpathWithCGImage:CGImageCreateWithImageInRect([p_w_picpath CGImage], rect1)];
NSString *filePath2 = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu2"]]; // 保存文件的名称
NSLog(@"filePath = %@",filePath);
BOOL result2 = [UIImagePNGRepresentation(p_w_picpath2)writeToFile:filePath2 atomically:YES];
NSLog(@"result2 = %d",result2);
//存入相册
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}