iphone image ALAsset problem

你说的曾经没有我的故事 提交于 2019-12-07 19:29:10

问题


First of all sorry for the crappy formatting. I dont know how to format the code here.I am having a problem with retrieving the image from the photo library. I have pasted my code Please help me. I am having this problem from many days.

here, I am storing the image path in the database using the referenceURL. It is in the

-(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]
}

I am storing the imageURL in the database. Then in another View Controller I am trying to retrive the image using the same url using the below code

  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);

The application crashes at this point without any error message. Can anyone please help me on this


回答1:


I found the solution. It was the problem with the last nslog. But I need to know why. the variable thethumbnail is declared with class scope. Has it got to do anything with blocks



来源:https://stackoverflow.com/questions/5063244/iphone-image-alasset-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!