/** 由图片生成缩略图 */ static NSImage *ATThumbnailImageFromImage(NSImage *image) { NSSize imageSize = [image size]; CGFloat imageAspectRatio = imageSize.width / imageSize.height; NSSize thumbnailSize = NSMakeSize(THUMBNAIL_HEIGHT * imageAspectRatio, THUMBNAIL_HEIGHT); NSImage *thumbnaiImage = [[NSImage alloc] initWithSize:thumbnailSize]; [thumbnaiImage lockFocus]; [image drawInRect:NSMakeRect(0, 0, thumbnailSize.width, thumbnailSize.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; [thumbnaiImage unlockFocus]; return thumbnaiImage; }
文章来源: Objective-C实现图片生成缩略图