[英]Efficient thumbnail creation in iPhone
在iPhone中从任意Web图像创建缩略图的最有效方法是什么?
the comparison of two method for fast creating thumbnail from image kindly see this link for detail http://www.cocoaintheshell.com/2011/01/uiimage-scaling-imageio/ or http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/ 从图像快速创建缩略图的两种方法的比较请看详细链接http://www.cocoaintheshell.com/2011/01/uiimage-scaling-imageio/或http://vocaro.com/trevor/blog/一十分之二千零九/ 12 /调整-A-UIImage的最右路/
for future , just copy pasting code from first one 为了将来,只需从第一个复制粘贴代码
First method, using UIKit 第一种方法,使用UIKit
void)buildGallery
{
for (NSUInteger i = 0; i < kMaxPictures; i++)
{
NSInteger imgTag = i + 1;
NYXPictureView* v = [[NYXPictureView alloc] initWithFrame:(CGRect){.origin.x = x, .origin.y = y, .size = _thumbSize}];
NSString* imgPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d", imgTag] ofType:@"jpg"];
UIImage* fullImage = [[UIImage alloc] initWithContentsOfFile:imgPath];
[v setImage:[fullImage imageScaledToFitSize:_thumbSize]];
[fullImage release];
}
Results of the benches gave me the following : 长凳的结果给了我以下内容:
Second method, using ImageIO 第二种方法,使用ImageIO
-(void)buildGallery
{
for (NSUInteger i = 0; i < kMaxPictures; i++)
{
NSInteger imgTag = i + 1;
NYXPictureView* v = [[NYXPictureView alloc] initWithFrame:(CGRect){.origin.x = x, .origin.y = y, .size = _thumbSize}];
NSString* imgPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d", imgTag] ofType:@"jpg"];
CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:imgPath], NULL);
CFDictionaryRef options = (CFDictionaryRef)[[NSDictionary alloc] initWithObjectsAndKeys:(id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailWithTransform, (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailFromImageIfAbsent, (id)[NSNumber numberWithDouble:_maxSize], (id)kCGImageSourceThumbnailMaxPixelSize, nil];
CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(src, 0, options); // Create scaled image
CFRelease(options);
CFRelease(src);
UIImage* img = [[UIImage alloc] initWithCGImage:thumbnail];
[v setImage:img];
[img release];
CGImageRelease(thumbnail);
}
he benches gave me this : 他长凳给了我这个:
You can see that using ImageIO is about 19% faster than UIKit, and also uses slightly less memory . 您可以看到使用ImageIO比UIKit快约19%,并且使用的内存略少 。
The only way that I've found so far that works on any images is to show it in an ImageView with the right size, and then create a bitmap from that view. 到目前为止我发现的唯一适用于任何图像的方法是在具有正确大小的ImageView中显示它,然后从该视图创建一个位图。
Far from efficient, though. 但是,远非有效率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.