0

如何仅访问 UIImagePickerControllerReferenceURL 的 MIME ext 部分?这是我在 NSLog -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 时得到的

UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=F61B754A-705C-4BFB-9965-DE34C7B93A2B&ext=PNG";

我只想访问 MIME 类型。当我使用以下方式将图像发送到我的网络服务器时:

NSData *imageData = UIImageJPEGRepresentation(_selectedImage, 1.0);

//non-important ASIFormDataRequest set-up
[request setData:imageData withFileName:uniqueString andContentType:@"image/jpeg" forKey:@"photo"];

画面一团糟。但是当我使用:

NSData *imageData = UIImagePNGRepresentation(_selectedImage);

//non-important ASIFormDataRequest set-up
[request setData:imageData withFileName:uniqueString andContentType:@"image/png" forKey:@"photo"];

图片很好。但是我上传的所有照片都不会是PNG。

4

3 回答 3

1

Dimitris 在这个线程上的回答就像一个魅力。我现在要继续打字,这样就不会被降级为微不足道的答案,然后自动成为评论。

于 2012-07-01T17:40:47.163 回答
1

要快速获取图像扩展名:

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
            if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
                let assetPath = info[UIImagePickerControllerReferenceURL] as! NSURL
                let ext = assetPath.absoluteString.componentsSeparatedByString("ext=")[1]
                 print(ext)
        }
    }
于 2016-11-16T12:58:35.437 回答
0

请尝试以下代码以从中extension提取UIImagePickerControllerReferenceURL

NSURL *referenceURL = @"assets-library://asset/asset.PNG?id=F61B754A-705C-4BFB-9965-DE34C7B93A2B&ext=PNG"; //put your reference URL here
NSString *fileExtension = [referenceURL.absoluteString componentsSeparatedByString:@"ext="][1];
于 2016-11-03T09:40:50.420 回答