当我将图像保存到文件时,保存的方向是错误的

时间:2012-04-10 18:43:27

标签: objective-c xcode image xcode4

当我将图像保存到文件时,它会以错误的方向保存。

- (void)saveImage:(UIImage *)image:(NSString *)imageName
{
   NSData *imageData = UIImagePNGRepresentation(image);         
   NSFileManager *fileManager = [NSFileManager defaultManager];   
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
       NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];         
   NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:
      [NSString stringWithFormat:@"%@.png", imageName]];
   [fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
}

感谢。

1 个答案:

答案 0 :(得分:6)

尝试另存为jpeg:

NSData * imageData = UIImageJPEGRepresentation(image,1.0);

如果您需要将其另存为PNG,请查看以下讨论: UIImagePNGRepresentation ..... writeToFile is always landscape