简体   繁体   中英

resizing an uiimage before writing it to documents directory

I have a question.I need to resize the image when I take an image using camera and picking the image from the photo library using uiimagepickercontroller and then write that resized image to the documents directory. So please help me with some reference on how to resize an uiimage.

Use the following:

UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
UIGraphicsEndImageContext();
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"resizedImage.jpg"];
[UIImageJPGRepresentation(newImage, 1.0) writeToFile:path atomically:YES];

您可以使用Trevor的库获得更多效果,不仅可以调整大小-正确调整图像大小

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM