내 문서 디렉토리에서 하나의 이미지가 이름이 Image1 인 이미지입니다.하나의 이미지를 복사하고 diff로 저장하는 방법. 문서 디렉토리의 이름
문서 디렉토리 폴더에 Image2라는 이름으로 같은 이미지를 복사하고 싶습니다.
제발, 어떻게 할 수 있습니까?
내 문서 디렉토리에서 하나의 이미지가 이름이 Image1 인 이미지입니다.하나의 이미지를 복사하고 diff로 저장하는 방법. 문서 디렉토리의 이름
문서 디렉토리 폴더에 Image2라는 이름으로 같은 이미지를 복사하고 싶습니다.
제발, 어떻게 할 수 있습니까?
는 다음 코드를 참조하십시오.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *imagePath1= [documentDirectory stringByAppendingPathComponent:@"image1.png"];
NSString *imagePath2= [documentDirectory stringByAppendingPathComponent:@"image2.png"];
[[NSFileManager defaultManager] copyItemAtPath:imagePath1 toPath:imagePath2 error:nil];
가져 오기는 그가 첫 번째 이미지에서 데이터와 같은 다른 이름으로 같은 데이터를 저장합니다
NSData *data = UIImageJPEGRepresentation(image1, 1.0);
NSString *[email protected]"image2.png"
NSString *fileName = [[stringPath stringByAppendingFormat:@"/"] stringByAppendingFormat:str];
NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
[data writeToFile:fileName atomically:YES];
나는 Fatch 이미지의 두 mathed을 가지고 이미지를 저장 : 당신은 다른 이름으로 이미지를 저장하는 문서 디렉토리에 저장하고 전달할 이미지 fatch :
-(UIImage *)loadImage:(NSString *)name
{
NSString* documentsDirectory=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
UIImage *res = [UIImage imageWithContentsOfFile:fullPath];
return res;
}
-(void)saveImage:(UIImage *)image withName:(NSString *)name
{
NSData *data = UIImageJPEGRepresentation(image, 1);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString* documentsDirectory=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
[fileManager createFileAtPath:fullPath contents:data attributes:nil];
}
감사를 너, 일하고있어. – Anki