【问题标题】:imagePickerController iPhoneimagePickerController iPhone
【发布时间】:2013-02-07 06:02:54
【问题描述】:

我的应用程序的功能是从相机胶卷中挑选图像,然后单击新图像然后上传。 当我从相机胶卷中选择现有图像时,它会给我一个像asset.jpg这样的图像名称(这是我想要的),但是当我点击我的新图像时,它返回一个内存位置而不是图像的名称(例如资产.jpg)。为了获得asset.jpg的名称,我必须首先使用

将图像存储到相机胶卷中
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
        {
            UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
            //UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
            [self.imageView setImage:nil];
        }

我不想。无论如何,我可以将图像名称作为asset.jpg 获取新单击的图像,而无需先将图像保存到相机胶卷。提前致谢。

编辑

UIImagePickerControllerReferenceURL 在从相机胶卷中选择现有图像时提供 URL,但返回新单击图像的临时内存位置

【问题讨论】:

    标签: ios objective-c xcode uiimagepickercontroller


    【解决方案1】:

    资产名称是在您保存照片时提供的,因此您需要这样做。我使用以下代码保存图像并获取其路径。

       ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
            // Request to save the image to camera roll
        [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation]completionBlock:^(NSURL *assetClickedURL, NSError *error){
            if (error) {
                NSLog(@"error saving image %@", [error localizedDescription]);
            } else
            {
    
                NSLog(@"image from camera saved at  %@", assetClickedURL);
                [self uploadImageAtassetURL:assetClickedURL];
            }
        }];
    

    【讨论】:

    • 但是我的即时点击和上传的目的没有实现,因为用户再次必须去相机胶卷挑选图像。
    • 并非如此。我已经编辑了代码以显示您可以从哪里获取assetURL,然后在该URL 上传图像。通过这样做,图像被保存在相册中,然后被上传。您还需要根据上传的位置来实施 upLoadImageAtAssetURL。
    猜你喜欢
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多