【发布时间】:2011-05-01 18:23:39
【问题描述】:
是否有任何解决方案可以“动态”创建具有良好性能的照片拼贴?! 我已经看过here,但这不是那么高效。
目的是创建一个快速的照片查看器,如 Apples photoapp。因此,我需要根据从应用程序创建或下载到应用程序的照片创建图块。
【问题讨论】:
标签: iphone ios core-graphics tiles
是否有任何解决方案可以“动态”创建具有良好性能的照片拼贴?! 我已经看过here,但这不是那么高效。
目的是创建一个快速的照片查看器,如 Apples photoapp。因此,我需要根据从应用程序创建或下载到应用程序的照片创建图块。
【问题讨论】:
标签: iphone ios core-graphics tiles
您最好的选择可能是使用 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);
请注意,这是凭记忆拼凑而成的,可能是错误的。请阅读文档以了解我在哪里搞砸了。
这里是关于这种技术的文档。
【讨论】: