当我将图像保存到文件时,它以错误的方向保存。
- (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];
}
谢谢。
最佳答案
尝试另存为 jpeg:
NSData *imageData = UIImageJPEGRepresentation(image,1.0);
如果您需要将其保存为 PNG,请查看此讨论: UIImagePNGRepresentation ..... writeToFile is always landscape
关于objective-c - 当我将图像保存到文件时,保存的方向是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094552/