Я думаю, что приведенный ниже код может помочь вам сделать то, что вы хотите, пожалуйста, удалите часть моего кода перед использованием в вашем приложении.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[appDelegate.objList setHidden:FALSE];
[self dismissModalViewControllerAnimated:YES];
UIImage *capturedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self performSelector:@selector(waitUntillImageCaptured:) withObject:capturedImage afterDelay:0.2];
}
-(void)waitUntillImageCaptured:(UIImage *)originalImage
{
UIImage *tempimg = originalImage;
//UIImageWriteToSavedPhotosAlbum(tempimg,nil,nil,nil);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGSize newSize = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(newSize);
[tempimg drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
NSString *strUser = [NSString stringWithFormat:@"%@",[imgDictName objectForKey:@"UsersName"]];
strUser = [strUser stringByReplacingOccurrencesOfString:@" " withString:@""];
[strUser retain];
NSString * strUserLocal = [strUser stringByAppendingString:@"temp.png"];
NSString *imagePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:strUserLocal];
UIImageView *tempView = [[UIImageView alloc] initWithImage:newImage];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(tempView.image)];
[tempView release];
if(data != nil) {
[data writeToFile:imagePath atomically:YES];
}
else{
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:NULL];
}
[pool release];
[self performSelector:@selector(thumbWithSideOfLength:) withObject:strUser afterDelay:0.3];
}
- (void)thumbWithSideOfLength:(NSString*)strImgName
{
[self onEditing];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToThumbImage = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@temp.png", strImgName]];
UIImage *thumbnail;
UIImage *mainImage = [UIImage imageWithContentsOfFile:fullPathToThumbImage];
UIImageView *mainImageView = [[UIImageView alloc] initWithImage:mainImage];
CGRect clippedRect = CGRectMake(0, 0, mainImage.size.width, mainImage.size.height);
CGFloat scaleFactor = 0.8;
UIGraphicsBeginImageContext(CGSizeMake(mainImage.size.width * scaleFactor, mainImage.size.height * scaleFactor));
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextClipToRect(currentContext, clippedRect);
CGContextScaleCTM(currentContext, scaleFactor, scaleFactor);
[mainImageView.layer renderInContext:currentContext];
thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(thumbnail);
[imageData writeToFile:fullPathToThumbImage atomically:YES];
userImageView.backgroundColor = [UIColor clearColor];
[userImageView imageFromImagePath:fullPathToThumbImage];
[mainImageView release];
}
Это, безусловно, решит ваши проблемы с изображением и позволит использовать этот общий метод в нескольких видах ...