gpt4 book ai didi

iphone - 创建图 block "on the fly"

转载 作者:行者123 更新时间:2023-11-29 11:23:03 26 4
gpt4 key购买 nike

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

目标是创建一个像 Apple 的照片应用程序一样的快速照片查看器。因此,我需要根据从应用程序创建或下载到应用程序的照片创建图 block 。

最佳答案

最好的选择可能是使用 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

关于iphone - 创建图 block "on the fly",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5850385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com