我有这段代码可以将图片放入我的UIImage
(与IB连接,名为' c1_1')并保存在我的目录文件夹中:
IBOutlet UIImageView *c1_1;
if (c1_1.image != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/ImagensApp/ImagensClientes/%@_%@_Cliente.jpg",list[0],abc]];
NSData* data = UIImageJPEGRepresentation(c1_1.image, 70);
[data writeToFile:path atomically:YES];
}
此代码有效,但我想调整图像大小以缩放200x200,我可以在保存之前完成此操作吗?
答案 0 :(得分:1)
缩放图像只需几行代码
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake( 0, 0, newSize.width, newSize.height )];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return( result );
}