解决方法
我在GitHub上找到了一个函数,它对我来说很好.
func resize(image: NSImage,w: Int,h: Int) -> NSImage { var destSize = NSMakeSize(CGFloat(w),CGFloat(h)) var newImage = NSImage(size: destSize) newImage.lockFocus() image.drawInRect(NSMakeRect(0,destSize.width,destSize.height),fromRect: NSMakeRect(0,image.size.width,image.size.height),operation: NSCompositingOperation.CompositeSourceOver,fraction: CGFloat(1)) newImage.unlockFocus() newImage.size = destSize return NSImage(data: newImage.TIFFRepresentation!)! }