CoreGraphics图像调整大小

dai*_*dai 3 iphone core-graphics ios ios5

此代码来自Apple的WWDC 2011 Session 318 - iOS Performance in Depth,并使用CoreGraphics从服务器托管的图像创建缩略图.

CGImageSourceRef src = CGImageSourceCreateWithURL(url);
NSDictionary *options = (CFDictionaryRef)[NSDictionary 
dictionaryWithObject:[NSNumber numberWithInt:1024
forKey:(id)kCGImageSourceThumbnailMaxPixelSize];

CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(src,0,options);
UIImage *image = [UIImage imageWithCGImage:thumbnail];
CGImageRelease(thumbnail);
CGImageSourceRelease(src); 
Run Code Online (Sandbox Code Playgroud)

但它不起作用,文档并没有真正帮助.在iOS文档CGImageSource CGImageSourceRef CGImageSourceCreateThumbnailAtIndex中可用

在Mac OS X v10.4或更高版本中

我怎样才能让它发挥作用?

编辑

这些是我得到的编译器错误:

  • 使用未声明的标识符'CGImageSourceRef'
  • 使用未声明的标识符'kCGImageSourceThumbnailMaxPixelSize'
  • 使用未声明的标识符'src'
  • 函数'CGImageSourceCreateThumbnailAtIndex'的隐式声明在C99中无效
  • 函数'CGImageSourceRelease'的隐式声明在C99中无效
  • 函数'CGImageSourceCreateWithURL'的隐式声明在C99中无效

dai*_*dai 15

男生错误.

没有添加 #import <ImageIO/ImageIO.h>