Skip to content

Instantly share code, notes, and snippets.

@hirokim
Created December 18, 2014 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirokim/2c29959d4a896493473e to your computer and use it in GitHub Desktop.
Save hirokim/2c29959d4a896493473e to your computer and use it in GitHub Desktop.
画像を合成する
/**
* 画像を合成する
*
*/
- (UIImage *)compositeImages:(NSArray *)array size:(CGSize)size
{
UIImage *image = nil;
// ビットマップ形式のグラフィックスコンテキストの生成
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
// 描画領域
CGRect rect = CGRectMake(0, 0, size.width, size.height);
for (id item in array) {
if (![item isKindOfClass:[UIImage class]]) {
continue;
}
UIImage *img = item;
[img drawInRect:rect];
}
// 現在のグラフィックスコンテキストの画像を取得する
image = UIGraphicsGetImageFromCurrentImageContext();
// 現在のグラフィックスコンテキストへの編集を終了
// (スタックの先頭から削除する)
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment