iphone图像ALAsset问题

发布于 2024-10-18 11:47:22 字数 2772 浏览 3 评论 0原文

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

在这里,我使用 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);

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2024-10-25 11:47:22

我找到了解决方案。是最后一个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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文