是否有任何解决方案可以“动态”创建具有良好性能的照片?? 我已经看过了here,但这并不是那么高效。
目的是创建像苹果photoapp这样的快速照片浏览器。因此,我需要根据从应用程序创建或下载到应用程序的照片创建切片。
答案 0 :(得分:2)
您最好的选择可能是使用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);
谨慎一点,这是从记忆中拼凑而成的,可能是错误的。请阅读文档,看看我搞砸了。
以下是有关此技术的文档。