在 iPhone 4S 上从 ALAsset 设置 fullScreenImage 比在 iPhone 4 上慢

发布于 2024-12-19 20:32:15 字数 1771 浏览 0 评论 0原文

我正在使用 ALAsset 从用户相机胶卷中检索照片,以将它们呈现在滚动视图上,就像照片应用程序一样。以下功能在 iPhone 4 (iOS 4.3.3) 上运行顺利,但在 iPhone 4S (iOS 5.0.0) 上运行不佳:每次页面更改时都会阻塞约 0.5 秒。问题可能出在哪里?

先感谢您!

- (UIView*) infinitePagingView:(InfinitePagingView*) infinitePagingView viewForPageIndex:(int) index
{
        ImageGalleryImageView *v = [[[ImageGalleryImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
    v.autoresizesSubviews = YES;
    v.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;

    if(photos.count<=index){
        return nil;
    }

    UIImage *theThumbnail = [UIImage imageWithCGImage:(CGImageRef) [[photos objectAtIndex:index] thumbnail]];
        [v setImageView: theThumbnail];
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        ALAsset *object = [photos objectAtIndex:index];
        ALAssetRepresentation *representation = [object defaultRepresentation];
        float version = [[[UIDevice currentDevice] systemVersion] floatValue];

        UIImageOrientation theOrientation;
        if (version >= 5.0){
            theOrientation = UIImageOrientationUp;
        }
        else{
            theOrientation = (UIImageOrientation) [representation orientation];
        }

        UIImage *theFullImage = [[UIImage imageWithCGImage:(CGImageRef)[representation fullScreenImage] scale:1.0 orientation: theOrientation] autorelease];                            
        dispatch_sync(dispatch_get_main_queue(), ^{
            [v setImageView: theFullImage];
        });
    });

        return v;
}

I'm retrieving photos from the user camera roll with ALAsset, to present them on a scrollview, like the photo app. The following function works smoothly on iPhone 4 (iOS 4.3.3) and not on iPhone 4S (iOS 5.0.0): it block on every change of page for about 0.5 seconds. Where can be the problem?

Thank you in advance!

- (UIView*) infinitePagingView:(InfinitePagingView*) infinitePagingView viewForPageIndex:(int) index
{
        ImageGalleryImageView *v = [[[ImageGalleryImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
    v.autoresizesSubviews = YES;
    v.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;

    if(photos.count<=index){
        return nil;
    }

    UIImage *theThumbnail = [UIImage imageWithCGImage:(CGImageRef) [[photos objectAtIndex:index] thumbnail]];
        [v setImageView: theThumbnail];
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        ALAsset *object = [photos objectAtIndex:index];
        ALAssetRepresentation *representation = [object defaultRepresentation];
        float version = [[[UIDevice currentDevice] systemVersion] floatValue];

        UIImageOrientation theOrientation;
        if (version >= 5.0){
            theOrientation = UIImageOrientationUp;
        }
        else{
            theOrientation = (UIImageOrientation) [representation orientation];
        }

        UIImage *theFullImage = [[UIImage imageWithCGImage:(CGImageRef)[representation fullScreenImage] scale:1.0 orientation: theOrientation] autorelease];                            
        dispatch_sync(dispatch_get_main_queue(), ^{
            [v setImageView: theFullImage];
        });
    });

        return v;
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文