1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 4 self.view.backgroundColor = [UIColor greenColor]; 5 6 //图片 7 UIImage *image = [UIImage imageNamed:@"myinformation_pic"]; 8 9 [self imageWithImageSimple:image scaledToSize:CGSizeMake(100, 100)]; 10 } 11 12 //压缩图片 13 14 - (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize 15 { 16 //开启图片上下文 17 UIGraphicsBeginImageContext(newSize); 18 19 //绘制图片 20 [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; 21 22 23 //取得当前图片上下文 24 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 25 26 //关闭图片上下文 27 UIGraphicsEndPDFContext(); 28 29 return newImage; 30 31 }
时间: 2024-10-10 17:17:14