tha*_*rai 0 iphone uiimagepickercontroller photo-gallery ios
嗨,我正在开发一个应用程序,其中有一个选项从iOS照片库中选择照片.我必须将选定的照片上传到服务器.要上传图像我正在使用Kaltura SDK,所以我处于无法直接发送UIImage到服务器的情况.我需要发送保存的图像文件路径.
为此,我找到了一个解决方案,即将选定的照片保存在特定的文件路径中,然后我将使用该文件路径.但问题是我不希望再次在手机内存中保存照片,因为这些照片已经存储在特定路径中.
那么有没有其他选项来重新保存图像文件路径而不再保存它?
Mut*_*awe 19
试试这个:
- (void)saveImage: (UIImage*)image
{
if (image != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"test.png" ];
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
}
}
- (UIImage*)loadImage
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"test.png" ];
UIImage* image = [UIImage imageWithContentsOfFile:path];
[self sendAction:path];
return image;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17878 次 |
| 最近记录: |