1

我正在使用这个精彩的教程为带有 phonegap 的 IOS 创建一个类似 Instagram 的应用程序

它很好用,但是当我尝试下载、存储照片并将照片传递给插件时,我收到错误消息

我的错误是:

Dec 19 14:36:58 iPhone-of-your-home Imagefilter [17418] <Error>: ImageIO: CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource failed with error code -15.

我的插件代码是:

-(void)none:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options
{
    //I think that here is the problem
    NSString *filePath = [options objectForKey:@"image"];
    // CREATE NSURL
    NSURL *fileNameAndPath = [NSURL URLWithString:filePath];
    NSLog(@"FILE PATH: %@",fileNameAndPath);

    // DEFINE OUR CIImage
    CIImage *beginImage = 
    [CIImage imageWithContentsOfURL:fileNameAndPath];
    CIContext *context = [CIContext contextWithOptions:nil];

    // DO ALL MODIFICATIONS HERE.


    CGImageRef cgimg = 
    [context createCGImage:beginImage fromRect:[beginImage extent]];
...
...
}

正如我在捕获图像并传递它时从控制台看到的那样,它的 URL 如下:

file://localhost/var/mobile/Applications/EFDAF913-6287-4B46-B2FE-F9B0D3349DDF/tmp/cdv_photo_031.jpg

虽然我下载的文件有一个类似的 URL

/var/mobile/Applications/EFDAF913-6287-4B46-B2FE-F9B0D3349DDF/Documents/img18.png
4

1 回答 1

0

您的 img18.png 文件位于 Documents 目录中。

首先,您必须使用以下方法获取指向该指针的指针:

NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

然后构建路径:

NSString *path = [docsDirectory stringByAppendingPathComponent:@"img18.png"];

否则,您已经在代码中知道问题出在哪里。

于 2013-02-07T14:48:32.597 回答