UIImageViewを使って画像を表示する際の画像サイズに関する注意点

iPhoneアプリで画像を表示する場合にUIImageViewを利用する事があると思うのだが、表示する画像のサイズが大きすぎると問題が発生する場合がある事が分かった。
例えば4096x4096ピクセルJPEG画像を以下のようなコードで画面上に表示しようとすると、アプリが異常終了してしまった。

@interface UIImageViewTestViewController : UIViewController {
    UIImageView *imageView;
}
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@implementation UIImageViewTestViewController
@synthesize imageView;
- (void)viewDidLoad {
    [super viewDidLoad];
    imageView.image = [UIImage imageNamed:@"bigImage.jpg"];
}
@end


出力されたエラーメッセージは以下。エラーメッセージの意味が良くわからないし、シュミレーターでは異常終了が発生しないので、原因の特定に時間を取られてしまった。

Program received signal:  “0”.
warning: check_safe_call: could not restore current frame


本来は以下のような感じに表示される予定であった(ViewのModeはAspect Fitに設定)。


ちなみに画像のサイズを2048x2048ピクセルにすると異常終了はしなかったのだが、画像が以下のような感じで壊れてしまった。


ここでUIImageクラスのリファレンス(http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006890-CH3-SW2)を確認してみると、「You should avoid creating UIImage objects that are greater than 1024 x 1024 in size.」とちゃんと書かれていた。ということで画像のサイズを1024x1024ピクセルに縮小すると問題なく表示されるようになった。