我无法在 iOS 中保存和检索图像。我通过这段代码得到 nil 图像:
-(NSString *)saveImageDataWithImage:(UIImage *)image
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *photoName = [NSString stringWithFormat:@"%ld.png",
(long)[[NSDate date] timeIntervalSince1970]];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:photoName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:getImagePath])
{
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:getImagePath atomically:YES];
}
return photoName;
}
-(UIImage *)GetImageFromPath:(NSString *)ImageName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:ImageName];
UIImage *thumbNail = [[UIImage alloc] initWithContentsOfFile:getImagePath];
return thumbNail;
}
为什么我得到零图像?
请帮我。