【问题标题】:iphone image ALAsset problemiphone图像ALAsset问题
【发布时间】:2011-02-21 07:11:21
【问题描述】:

首先对糟糕的格式感到抱歉。我不知道如何在这里格式化代码。我在从照片库中检索图像时遇到问题。我已经粘贴了我的代码请帮助我。我从很多天都遇到了这个问题。

在这里,我使用 referenceURL 将图像路径存储在数据库中。它在

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    NSURL *imageUrl = [info  valueForKey:UIImagePickerControllerReferenceURL];

    NSURL *imageUrl = [info  valueForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc]init];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        NSLog(@"asset");
        CGImageRef iref = [myasset thumbnail];
        if(iref)
        {
            NSLog(@"ifref");
            UIImage *thethumbnail = [UIImage imageWithCGImage:iref];
            NSLog(@"the thumbnail %@",thethumbnail);
            [[self photo]setImage:thethumbnail];
            lpdel.imageurl = UIImageJPEGRepresentation (thethumbnail, 1);
        }
    };

    ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
    {
        NSLog(@"failed");
        NSLog(@"cant get image -- %@",[myerror localizedDescription]);
    };

    if (imageUrl) {
        NSLog(@"if url");
        [assetLibrary assetForURL:imageUrl
                      resultBlock:resultblock
                     failureBlock:failureblock];

        //lpdel.imageurl =imageUrl;

        NSLog(@"the image string    %@",lpdel.imageurl);
        NSLog(@"lpdel.image%@",lpdel.imageurl);
        [picker dismissModalViewControllerAnimated:YES];
        [imageUrl release];
    }
    [picker dismissModalViewControllerAnimated:YES];
    [picker release]
}

我将 imageURL 存储在数据库中。然后在另一个视图控制器中,我尝试使用以下代码使用相同的 url 检索图像

  ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        NSLog(@"asset");
        CGImageRef iref = [myasset thumbnail];
        if(iref)
        {
            NSLog(@"ifref");
            thethumbnail = [UIImage imageWithCGImage:iref];
            NSLog(@"the thumbnail to upload  %@",thethumbnail);
            [self uploadImage:UIImageJPEGRepresentation (thethumbnail, 1)];
            //[[self photo]setImage:thethumbnail];
        }
    };

    ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
    {
        NSLog(@"failed");
        NSLog(@"cant get image -- %@",[myerror localizedDescription]);
    };

    if (image) 
    {
        NSLog(@"if url");
        ALAssetsLibrary *assetLibrary = [[[ALAssetsLibrary alloc]init]autorelease];
        NSLog(@"url");
        [assetLibrary assetForURL:image
                      resultBlock:resultblock
                     failureBlock:failureblock];
    }
NSLog(@"the thumbnail %@",thethumbnail);

此时应用程序崩溃,没有任何错误消息。谁能帮我解决这个问题

【问题讨论】:

  • @waqas raja 感谢您的编辑。请帮我解决这个问题
  • 您可以通过选择代码行然后单击括号按钮来格式化代码块 { }
  • 谢谢。但是你能帮我解决我的问题吗?我真的很需要它
  • 尝试开启僵尸——你可能正在访问一个免费的参考...stackoverflow.com/a/5387006/210171

标签: iphone image uiimagepickercontroller exif alasset


【解决方案1】:

我找到了解决方案。这是最后一个nslog的问题。但我需要知道为什么。变量 thethumbnail 是在类范围内声明的。它与块有什么关系吗

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 2011-03-23
    • 1970-01-01
    • 2011-09-22
    • 2012-03-07
    相关资源
    最近更新 更多