gpt4 book ai didi

ios - 将图像保存到文档目录并检索电子邮件附件

转载 作者:IT王子 更新时间:2023-10-29 07:32:03 26 4
gpt4 key购买 nike

我在计算 NSBundle 和 DocumentDirectory 数据时遇到问题,我有一张相机图片“imageView”,我正在将其保存到 NSDocumentDirectoy然后想要检索它以附加到电子邮件中,

这里是保存代码:

- (IBAction)saveImage {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
UIImage *image = imageView.image; // imageView is my image from camera
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
}

这里是新的获取数据的代码:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
NSData *myData = [[[NSData alloc] initWithContentsOfFile:appFile] autorelease];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"savedImage"];

最佳答案

- (IBAction)getImage {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
}

这应该可以帮助您入门!

关于ios - 将图像保存到文档目录并检索电子邮件附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2037432/

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