UIImageJPEGRepresentation抛出EXC BAD ACCESS

时间:2011-12-15 16:03:24

标签: cocoa-touch image uikit exc-bad-access uiimagejpegrepresentation

我有功能,它接收了2个参数 - 图像和数字。下面的函数抛出EXC BAD ACCESS行“imgData = UIImageJPEGRepresentation(image,1.0);”。我不知道为什么:-(任何想法?

- (void)saveImages:(UIImage*)image row:(int)row {
  if (image != nil) {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString* path1 = [documentsDirectory stringByAppendingPathComponent: 
                      [NSString stringWithFormat:@"%i.JPEG", row]];
    NSString* path2 = [documentsDirectory stringByAppendingPathComponent: 
                      [NSString stringWithFormat:@"%is.JPEG", row]];

    NSData* imgData;
    imgData = UIImageJPEGRepresentation(image, 1.0);
    [imgData writeToFile:path1 atomically:YES];

    [self rotateIcon:image];
    image = [self imageWithImage:image];
    NSData* smalImgData = UIImageJPEGRepresentation(image, 1.0);
    [smalImgData writeToFile:path2 atomically:YES];
  }
}

0 个答案:

没有答案