【问题标题】:Finding filepath of an UIImage in Objective-C在 Objective-C 中查找 UIImage 的文件路径
【发布时间】:2011-09-10 22:27:45
【问题描述】:

在我的应用程序中,您使用 UIImagePickerControllerDelegate 选择图像,所以我有一个 UIImage。现在我需要该图像的文件路径。

有关应用程序的更多信息:我正在尝试修改/编辑选定的 PNG 图像。我需要能够访问所选图像的每个像素。我找到了有关如何访问像素的源代码,但代码依赖于通过文件路径加载图像,我还没有找到任何使用 UIImage 的方法。我试过了:

CGImageRef si = [imageView.image CGImage];
CGDataProviderRef src = CGImageGetDataProvider(si);
CGImageRef img = CGImageCreateWithPNGDataProvider(src, NULL, NO, kCGRenderingIntentDefault);

但这只会给我一个错误:“: CGDataProviderGetSize: size is too large for this function.”

(见iPhone SDK: accessing indexed color PNG images

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    选择图像时,您的代表会在ImagePickerController上获得回调:didfinishpickingmediawithinfo:该呼叫包括 info parameter,这是词典。 keys 之一为您提供文件 URL。可以使用path 方法将文件 URL 转换为路径。

    【讨论】:

    • 我在文档中看到该方法签名已被弃用,但使用正确的签名- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 只会给我键和值“键:UIImagePickerControllerMediaType,值:public.image 键:UIImagePickerControllerOriginalImage,值: "
    猜你喜欢
    • 2017-06-02
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2017-03-11
    • 2020-02-29
    相关资源
    最近更新 更多