从iphone摄像头拍照时收到iphone内存警告问题
当我从iphone摄像头拍摄快照时出现问题,然后我在设备控制台“已接收内存警告”上收到此错误。当我从iphone照片库中选取快照时,我没有收到任何内存警告问题。这是下面的代码从iphone摄像头拍照时收到iphone内存警告问题,iphone,objective-c,memory-management,Iphone,Objective C,Memory Management,当我从iphone摄像头拍摄快照时出现问题,然后我在设备控制台“已接收内存警告”上收到此错误。当我从iphone照片库中选取快照时,我没有收到任何内存警告问题。这是下面的代码 -(IBAction)uploadImageBtn:(id)sender { UIButton *btn = (UIButton *)sender; @try { UIImagePickerController *pickImage
-(IBAction)uploadImageBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
@try
{
UIImagePickerController *pickImage = [[UIImagePickerController alloc]init];
pickImage.delegate = (id)self;
if (btn.tag == 2)
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary ])
{
pickImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:pickImage animated:YES completion:nil];
}
else
{
UIAlertView *alertVw = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Photo library not exist" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertVw show];
}
}
else if (btn.tag == 3)
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera ])
{
pickImage.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:pickImage animated:YES completion:nil];
}
else
{
UIAlertView *alertVw = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Camera not working " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertVw show];
}
}
}
@catch (NSException *exception)
{
NSLog(@"exception %@",exception);
}
}
// uiimage picker view controller delegate method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
@try {
[picker dismissViewControllerAnimated:YES completion:nil];
// Edited image works great (if you allowed editing)
myImage = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
myImage = [info objectForKey:UIImagePickerControllerOriginalImage];
myImage = [myImage fixOrientation];
// AND do whatever you want with it, (NSDictionary *)info is fine now
// fixOrObj = [[fixorientation alloc]init];
// myImage = [fixOrObj fixOrientation];
dataObj = UIImageJPEGRepresentation(myImage, 0);
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.delegate = (id)self;
HUD.labelText = @"Uploading image";
[self performSelector:@selector(uploadimages) withObject:nil afterDelay:1.0];
}
@catch (NSException *exception)
{
NSLog(@"exception %@",exception);
}
}
kinsly解决了这个问题我尝试了两天,但没有成功你可以做的是缩小照片的大小。因为你正在拍摄的照片分辨率高,尺寸大,所以首先你可以缩小尺寸,如下所示
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
CGSize sizeCropped = CGSizeMake(602, 450);//you can give any size
UIImage *theimage = nil;
theimage = [yourclassname imageWithImage:image scaledToSize:sizeCropped];
//you can do here whatever you want with theImage
[imgPicker dismissViewControllerAnimated:YES completion:nil];
}
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
让我知道它是否工作
编码快乐 当显示UIImagePickerController时,内存警告是正常的。只有当此内存警告使应用程序崩溃时,您才应该担心。使用UIImagePickerController打开摄像头是内存扩展操作。那么解决方法是什么呢?我不理解你的这个术语:使用UIImagePickerController打开摄像头是内存扩展操作