【问题标题】:Creating tiles "on the fly"“即时”创建图块
【发布时间】:2011-05-01 18:23:39
【问题描述】:

是否有任何解决方案可以“动态”创建具有良好性能的照片拼贴?! 我已经看过here,但这不是那么高效。

目的是创建一个快速的照片查看器,如 Apples photoapp。因此,我需要根据从应用程序创建或下载到应用程序的照片创建图块。

【问题讨论】:

    标签: iphone ios core-graphics tiles


    【解决方案1】:

    您最好的选择可能是使用 Core Graphics 和 ImageI/O

    CGImageRef image = ...; // the big image to slice, don't draw with this image or it will decompress and might chew up all your memory
    NSURL *url = ...; // the url for this slice
    NSString *uti = @"public.jpeg"; // just an example, you should get the correct one for your images
    CGSize sliceSize = 256.0; // for example
    size_t column = 0;
    size_t row = 0; // row and column should vary across your image
    CGFloat colWidth = 256.0; // should account for the final column not being 256
    CGFloat rowWidth = 256.0; // should account for the final row not being 256
    CGRect sliceRect = CGRectMake(floor(column * sliceSize), floor(row * sliceSize),
                                        floor(colWidth), floor(rowHeight));
    CGImageRef slicedImage = CGImageCreateWithImageInRect(image, sliceRect);
    if(NULL == slicedImage) {
        NSLog(@"hosed image");
    }
    CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)url, (CFStringRef)uti, 1, NULL);
    CGImageDestinationAddImage(destination, slicedImage, NULL);
    if(!CGImageDestinationFinalize(destination)) {
        NSLog(@"hosed write of %@", [url path]);
    }
    CFRelease(destination);
    CGImageRelease(slicedImage);
    

    请注意,这是凭记忆拼凑而成的,可能是错误的。请阅读文档以了解我在哪里搞砸了。

    这里是关于这种技术的文档。

    http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGImage/Reference/reference.html#//apple_ref/c/func/CGImageCreateWithImageInRect

    http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/ImageIOGuide/imageio_basics/ikpg_basics.html

    【讨论】:

    • 不幸的是,它的性能不是很好。我想不可能在可接受的时间内“即时”创建图块。但感谢您的回答!
    猜你喜欢
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 2011-10-23
    • 2011-01-12
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多