在我的应用中,我需要将6张图片上传到服务器。我捕获图像然后上传它然后转到下一个并执行相同的操作。
当我到达第5张图像并收到3或4个内存警告后,应用程序崩溃
以下是图片选择器的代码
-(void) TakePhotoWithCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker1 = [[UIImagePickerController alloc] init];
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
picker1.allowsEditing = YES;
picker1.delegate = self;
[self presentViewController:picker1 animated:YES completion:nil];
}
}
完成捕获时的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage * img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[picker dismissViewControllerAnimated:YES completion:nil];
UIButton * tappedBtn = (UIButton *) [self.horizontalScrollView viewWithTag:chosenImgBtnTag];
[tappedBtn setImage:img forState:UIControlStateNormal];
[self useImage:img]; // this method upload the image to the server
info = nil;
}
这是setImage的方法
- (void) useImage:(UIImage *) image {
currentImageToUpload = image;
[self showLoadingIndicatorOnImages];
[[CarAdsManager sharedInstance] uploadImage:image WithDelegate:self];
}
所以请在这件事上提供帮助吗?
答案 0 :(得分:0)
您应该在捕获图像后重新调整(480, 480)
图像的大小,
UIImage *getNewImage;
CGSize newSize = CGSizeMake(480, 480);
UIGraphicsBeginImageContext(newSize);
[capturedImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
getNewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
它会将“getNewImage”作为图像返回。您可以上传此图片。它会减少你的内存警告崩溃。