繁体   English   中英

如何在iOS中将图片从图库上传到支持文件?

[英]How to upload images from gallery to a supporting files in iOS?

我是iOS的新手,我已经完成了一个创建小应用程序的任务,该应用程序允许用户从图库中选择图像,并且所选图像会显示在UIImage视图中,并应保存在支持文件下的images文件夹中。

当前图像使用以下代码块保存在documents文件夹下:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
localFilePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
self.imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];

如何将所选图像保存在支持文件中的图像文件夹下?

以下是我项目中的文件夹结构

图像可以保存在手机存储器中,而不是图像文件夹中。如果您想将图像保存在项目中,则可以通过核心数据或sqlite数据库保存,但是看不到图像。图片文件夹。

不知道为什么需要在images文件夹上显示它,但据我所知我不可能。

根据您在评论中给出的要求,我编辑了之前的答案。

   MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
   mail.mailComposeDelegate = self;
   [mail setSubject:@"find attachment"];
   UIImage *selectedImage = "put your image from your image view/ selected gallery image"
   NSData *myData = UIImagePNGRepresentation(selectedImage);
   [mail addAttachmentData:myData mimeType:@"image/png" fileName:@"coolImage.png"];

   // set email body
   NSString *emailBody = @"My cool image is attached";
   [mail setMessageBody:emailBody isHTML:NO];
   [self presentModalViewController:mail animated:YES];

祝一切顺利

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM