如何从iOS中的iPhone照片库中选择图像名称和图像
我正在从iPhone照片库中选择一个图像,或者从相机胶卷中选择其他方式。 我没有任何问题就这样做了。 但我需要检索从库中选择图像名称。 但是我无法从图库中选择图像名称。 我的要求是我想从照片库中选择图像和图像名称并发送聊天墙。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:nil]; UIImage *image =[[UIImage alloc] init]; image =[info objectForKey:@"UIImagePickerControllerOriginalImage"]; NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"]; Here i am able to get the image path like this: assets-library://asset/asset.JPG?id=9F983DBA-EC35-42B8-8773-B597CF782EDD&ext=JPG imageName = [imagePath lastPathComponent]; NSData *imageData; NSString *extensionOFImage =[imageName substringFromIndex:[imageName rangeOfString:@"."].location+1 ]; if ([extensionOFImage isEqualToString:@"jpg"]) { imageData =UIImagePNGRepresentation(image); } else { imageData = UIImageJPEGRepresentation(image, 1.0); } int imageSize=imageData.length/1024; NSLog(@"imageSize--->%d", imageSize); if (imageName!=nil) { NSLog(@"imageName--->%@",imageName); here the imageName is showing like this “asset.jpg”.. } else { NSLog(@"no image name found"); } } -(void)sendMessage:(NSString *)messageTxt { str=@"Ryan"; mesText=messageTxt; senderImgName=[UIImage imageNamed:imageName]; here the imageName is showing like this = asset.jpg but senderImgName= null. NSString *str1=imageName; NSLog(@"sender image name is:%@",senderImgName); imgData=[NSData dataWithData:UIImageJPEGRepresentation(senderImgName, 0)]; finalImagePath=[imgData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]; NSLog(@"Final image path is:%@", finalImagePath); }
使用Photos框架并导入Photos / Photos.h
#import "Photos/Photos.h"
在imagePickerController函数中添加以下内容以从Photo库中获取所选图像的文件名:
NSURL *imagePath = [editingInfo objectForKey:UIImagePickerControllerReferenceURL]; PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[imagePath] options:nil]; NSString *filename = [[result firstObject] filename]; NSLog(@"[filename ] %@", filename );
结果如下:[filename] IMG_0012.JPG
- Hotels.com和Apple Pay
- 检测video开始在WKWebView中播放
- 如何在Android的Artoolkitplus中获得MarkerId
- 如何获取在WKinterfaceTable中的WKInterfacebutton的索引?
- AudioKit v4.2上的AKRhodesPiano错误(粉碎)
- Azure DocumentDB通过Obj-c查询REST API时发生间歇性401错误
- UIGraphicsBeginImageContext与CGBitmapContextCreate
- 如何快速从越狱的iOS设备上的捆绑ID获取应用程序的目录?
- 错误:未定义不是一个对象(评估\'RCTWebSocketManager.connect \')