首页 > 代码库 > 拍照内存警告导致崩溃的解决
拍照内存警告导致崩溃的解决
#import <MobileCoreServices/UTCoreTypes.h>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; UIImage *originalImage, /*editedImage,*/ *imageToSave; SQImagePickerController *sqImgPicker = (SQImagePickerController *)picker; // 处理静态照片 if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {// editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage]; originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];// if (editedImage) {// imageToSave = editedImage;// }// else { imageToSave = originalImage;// } // 将静态照片(原始的或者被编辑过的)保存到相册(Camera Roll) // UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil); // 根据图片控件的尺寸缩放照片(只是为了显示效果。实际传输时依然使用原始照片) // UIImage* scaledImage = [self imageWithImage:imageToSave scaledToSize:self.imagePhoto.bounds.size]; //对图片大小进行压缩-- imageToSave = [self imageWithImage:imageToSave scaledToSize:CGSizeMake(158, 100)]; if (_flagType==1) { NSDictionary *data = http://www.mamicode.com/@{@"paizhaoImage" : imageToSave}; [SQBaseCell sharedInstance].paizhaoImageData = data; // 缓存传输照片 self.imagePicture = imageToSave; [self.allSqInfoView[self.selectedIndex] didrecordValidate:self.tempPaiButton conValue:@"YES" showText:@""]; for (int i=(int)self.imageDicArray.count-1; i>=0; i--) { if ([[self.imageDicArray[i] objectForKey:@"key"] isEqualToString:self.imgButton.accessibilityHint]) { [self.imageDicArray removeObject:self.imageDicArray[i]]; } } NSDictionary *tempDic = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@", self.imgButton.accessibilityHint],@"key", imageToSave,@"imageData", sqImgPicker.fileType, @"fileType", nil]; [self.imageDicArray addObject:tempDic]; } else if(_flagType==2) { NSDictionary *data = http://www.mamicode.com/@{@"imgData" : imageToSave}; SQInfoView *sqInfoView=self.allSqInfoView[self.selectedIndex]; [sqInfoView insertSubView:[UIButton new] clickView:self.imgButton data:data]; } } [self dismissViewControllerAnimated:YES completion:Nil];}
//对图片尺寸进行压缩---(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize{ // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this new context, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage;}
拍照内存警告导致崩溃的解决
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。