gpt4 book ai didi

objective-c - iOS : Saving from current UIImageView to Photo Album Failed - Unable to save to photo album

转载 作者:行者123 更新时间:2023-11-28 17:37:22 24 4
gpt4 key购买 nike

我想做一个应用程序,在按下按钮时从当前主 UIImageView 保存图像并将其保存到相册。

我的程序所做的是在我按下“保存到相册”按钮后显示错误。可能是我的代码结构不对。或者谁能​​告诉我正确的代码结构?

这是我到目前为止的进展。

-(IBAction) saveToPhotoAlbum{

NSString *saveMyPhoto=[NSHomeDirectory() stringByAppendingPathComponent:@"image.png"];

UIImage *saved=[UIImage imageWithContentsOfFile:saveMyPhoto];

NSData *imageData = [NSData dataWithContentsOfFile:(NSString *)UIImagePNGRepresentation(saved)];
[imageData writeToFile:(NSString *)saved atomically:YES ];

UIImageWriteToSavedPhotosAlbum(saved, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);



- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;


if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}

最佳答案

你应该给一个正确的路径来保存图像。一个也是读写的,检查文档目录,NSString * docPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"],然后使用相同的方法添加文件名 -stringByAppendingPathComponent: 或只需创建一个包含两个内容的格式化字符串

关于objective-c - iOS : Saving from current UIImageView to Photo Album Failed - Unable to save to photo album,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9468056/

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