2013-03-16 61 views
0

在我的应用程序中,我使用相机和照片库来获取UIImage ...挑选图像后,我需要将其转换为NSData,并希望将此数据传递给名为addBlobToContainer的方法:.. ..但它给了EXC_BAD_ACCESS .... 我该如何解决这个问题?EXC_BAD_ACCESS在检索NSData

这里是我的照片库中的代码...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    image.image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; 
    imageData = [NSData dataWithData:UIImageJPEGRepresentation(image.image,1)]; 
    guid = [Guid randomGuid]; 
    NSLog(@"%@", guid.description); 
    GUID = guid.description; 
    NSLog(@"GUID===%@",GUID); 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    NSLog(@"STRIMAGEDATA===%@",imageData); 

    if ([imageData length] != 0) 
    { 
     NSLog(@"%@",imageData); 
     [client addBlobToContainer:newcontainer blobName:GUID contentData:imageData contentType:@"application/octet-stream" withBlock:^(NSError *error) 
     { 
      if (error) 
      { 
      NSLog(@"%@",[error localizedDescription]); 
      } 
       else 
       { 
       NSLog(@"blob inserted suuccessfully…"); 
       imageURL = [serviceURL stringByAppendingString:[NSString stringWithFormat:@"%@.jpg",GUID]]; 
       NSLog(@"IMAGEURL=%@",imageURL); 
       } 
      }];-->EXC_BAD_ACCESS 
    } 
} 
+0

向我们展示'imageData'的声明。它是“强”还是“弱”? – Sulthan 2013-03-16 12:19:16

+0

也是serviceURL和GUID的声明。 – 2013-03-16 12:20:14

+0

不要给你的标识符名称,如“图像”。使用适当的枚举UIImagePickerControllerEditedImage不是你定义的字符串(这可能是问题?) – 7usam 2013-03-16 12:22:48

回答

3

您没有访问属性,您要访问的属性后面的变量。如果您希望数据自动由该属性保留,请使用属性设置器,例如self.imageData = ...而不是imageData = ...

1

尝试

self.imageData = UIImageJPEGRepresentation(image.image,1);