iOS SDK で 画像ファイルからCGImageを作成する時の注意

//ファイルパス

NSString *filepath = ... 

 

// 以下はエラーが発生

CGImageRef image  = [[UIImage alloc] initWithContentsOfFile:filepath].CGImage; 

 

// 以下はエミュレータでは動いたが、実機ではエラーが発生

CGImageRef image  = [UIImage imageWithContentsOfFile:filepath].CGImage;

 

// 以下だと正常に動く

UIImage *uim = [UIImage imageWithContentsOfFile:filepath];

CGImageRef image  = uim.CGImage;