【发布时间】:2013-10-25 05:15:50
【问题描述】:
我对处理图像有点陌生,有很多我不知道的事情,所以请多多包涵。基本上我用相机拍摄图像,并在UIImageView 中呈现,这是 60:80 的小视图。图片会自动调整大小以适合UIImageView,一切看起来都很好。
我的问题是 - 我需要做更多的图像操作(为了最大限度地提高效率),还是仅此而已?
【问题讨论】:
标签: iphone image-resizing
我对处理图像有点陌生,有很多我不知道的事情,所以请多多包涵。基本上我用相机拍摄图像,并在UIImageView 中呈现,这是 60:80 的小视图。图片会自动调整大小以适合UIImageView,一切看起来都很好。
我的问题是 - 我需要做更多的图像操作(为了最大限度地提高效率),还是仅此而已?
【问题讨论】:
标签: iphone image-resizing
请使用以下代码,这将为您提供更好的缩略图
-(UIImage *)generatePhotoThumbnail:(UIImage *)image
{
CGSize size = image.size;
CGSize croppedSize;
CGFloat ratio = 120.0;
CGFloat offsetX = 0.0;
CGFloat offsetY = 0.0;
if (size.width > size.height) {
offsetX = (size.height - size.width) / 2;
croppedSize = CGSizeMake(size.height, size.height);
} else
{
offsetY = (size.width - size.height) / 2;
croppedSize = CGSizeMake(size.width, size.width);
}
CGRect clippedRect = CGRectMake(offsetX * -1, offsetY * -1, croppedSize.width, croppedSize.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
CGRect rect = CGRectMake(0.0, 0.0, ratio, ratio);
UIGraphicsBeginImageContext(rect.size);
[[UIImage imageWithCGImage:imageRef] drawInRect:rect];
UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRelease(imageRef);
return thumbnail;
}
【讨论】:
Resize image function 将是:
-(UIImage *)resizeImage:(CGSize)imgSize
UIGraphicsBeginImageContext(imgSize);
[image drawInRect:CGRectMake(0,0,imgSize.width,imgSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Save 用unique names 调整了document directory 中的图像大小。后来access thumbnail image从document directory。
如果图像数量为more,则使用lazy loading 个图像来显示图像。
【讨论】:
如果您对图片的显示方式感到满意,那么您不需要任何额外的代码。图像视图为您重新缩放图像没有问题,而且它们在这方面非常有效,所以不用担心。
【讨论】: