iphone图像ALAsset问题 [英] iphone image ALAsset problem

查看:124
本文介绍了iphone图像ALAsset问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

我将imageURL存储在数据库中。然后在另一个View Controller中我试图使用相同的url使用下面的代码来检索图像

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

推荐答案

我找到了解决方案。这是最后一个nslog的问题。但我需要知道原因。使用类范围声明变量thethumbnail。是否必须对块进行任何操作

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

这篇关于iphone图像ALAsset问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆