gpt4 book ai didi

ios - 如何获取iPhone中图库中选择的图像的路径?

转载 作者:行者123 更新时间:2023-11-29 03:27:23 27 4
gpt4 key购买 nike

我有五个按钮。在每个按钮操作上。我打开图库并选择一个图像。但问题是在每个按钮操作上都有相同的路径。

UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];

NSData* imageData = UIImagePNGRepresentation(image);

NSString * imageName = @"Myimage.png";


NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString* documentsDirectory = [paths objectAtIndex:0];

NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
NSLog(@"fullPathToFile=%@",fullPathToFile); //important line

[imageData writeToFile:fullPathToFile atomically:NO];

最佳答案

初始设置全局变量 int countVal = 1;

NSString * imageName = [NSString stringWithformat:@"%d.png",countVal]; // Imgae_name set here
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
NSLog(@"fullPathToFile=%@",fullPathToFile); //important line
[imageData writeToFile:fullPathToFile atomically:NO];
count +=1; // Increment count here

关于ios - 如何获取iPhone中图库中选择的图像的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20292085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com