简体   繁体   English

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

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

I am a newbie to iOS and I have given a task of creating a small app, which allows user to select image from the gallery and selected image gets displayed in the UIImage view and should get saved in images folder under supporting files. 我是iOS的新手,我已经完成了一个创建小应用程序的任务,该应用程序允许用户从图库中选择图像,并且所选图像会显示在UIImage视图中,并应保存在支持文件下的images文件夹中。

Currently image gets saved under documents folder, using following block of code: 当前图像使用以下代码块保存在documents文件夹下:

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

How can I save selected image under image folder in supporting files? 如何将所选图像保存在支持文件中的图像文件夹下?

Following is the folder structure in my project 以下是我项目中的文件夹结构

The image can be able to save in the phone memory not in the images folder what you have, If you want to save the image with in your project you can able to save through core data or sqlite database but you cannot see the image in your images folder. 图像可以保存在手机存储器中,而不是图像文件夹中。如果您想将图像保存在项目中,则可以通过核心数据或sqlite数据库保存,但是看不到图像。图片文件夹。

Am not sure why you need to show that on the images folder but its not possible i think according to my knowledge. 不知道为什么需要在images文件夹上显示它,但据我所知我不可能。

Based on your requirement which is given by you on comment I have edited my previous answer. 根据您在评论中给出的要求,我编辑了之前的答案。

   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];

All the best 祝一切顺利

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

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