UIImageデータから任意のサイズを切り取る
UIImage *img_bf = [UIImage imageNamed:@"hoge.png"];
UIImage *img_af;
CGRect rect = CGRectMake(30, 30, 200, 100); // 切り取る場所とサイズを指定
UIGraphicsBeginImageContext(rect.size);
[img_bf drawAtPoint:rect.origin];
img_af = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
よくわかる?解説
細かく見ていくと結構簡単な処理です。
UIImage *img_bf; ← リサイズ前のUIImageを取得
UIImage *img_af; ← リサイズ後のUIImageを準備しておく
CGRect rect = CGRectMake(100, 200, 120, 100); ← 切り取る場所とサイズを指定
UIGraphicsBeginImageContext(rect.size); ← リサイズする大きさのコンテキストを作成
[img_bf drawInRect:CGRectMake(0, 0, width, height)]; ← その領域に描画してみる
img_af = UIGraphicsGetImageFromCurrentImageContext(); ← 描画されたUIImageを取得
UIGraphicsEndImageContext() ← 作った画面外描画領域を破棄(後片付けみたいなもんです)
最終更新:2013年02月27日 16:08