UIImageクラスは、画像データを管理するクラスであり、背景、ボタン内などに画像を表示する場合、画像データUIImageオブジェクトとしてから、UIImageViewなどでUIImageクラスのデータを使い、画像を表示させることが出来ます。




UIImageの宣言

// 画像ファイル名を指定したUIImageの生成例
UIImage *image = [UIImage imageNamed:@"hoge.png"];

主要なプロパティ

CGImage
Quartzイメージのデータを返す。
※読み取りのみ
例)CGImageRef imageRef = [image CGImage];

imageOrientation
レシーバのイメージの向きを返す。
※読み取りのみ
例)UIImageOrientation imageOrient = image.imageOrientation;
イメージの向き
UIImageOrientationUp 基本
UIImageOrientationDown 180度回転
UIImageOrientationLeft 90度左に回転
UIImageOrientationRight 90度右に回転
UIImageOrientationUpMirrored 反転
UIImageOrientationDownMirrored 反転して180度回転
UIImageOrientationLeftMirrored 反転して90度左に回転
UIImageOrientationRightMirrored     反転して90度右に回転    

size
対象のイメージのサイズ(幅)を返す。
※読み取りのみ
例)CGSize imageSize = image.size;

主要なクラスメソッド

imageNamed:
 + (UIImage *)imageNamed:(NSString *)name
引数に指定されたファイル名のイメージオブジェクトを作成
例)UIImage *image = [UIImage imageNamed:@"hoge.png"];

imageWithCGImage:
 + (UIImage *)imageWithCGImage:(CGImageRef)cgImage
引数に指定されたQuartzイメージのオブジェクトを作成
例)UIImage *image = [UIImage imageWithCGImage:imageRef];

imageWithContentsOfFile:
 + (UIImage *)imageWithContentsOfFile:(NSString *)path
引数に指定されたファイルパスのイメージをロードし、そのイメージオブジェクトを作成
例)UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"hoge" ofType:@"png"]];

imageWithData:
 + (UIImage *)imageWithData:(NSData *)data
引数に指定されたイメージデータを使用し、イメージオブジェクトを作成
例)UIImage *image = [UIImage imageWithData: imageData];

主要なインスタンスメソッド

drawAtPoint:
 - (void)drawAtPoint:(CGPoint)point
引数に指定された座標で現在のコンテキストを描画する
例)[image drawAtPoint:CGPointMake(100,100)];

initWithCGImage:
 - (id)initWithCGImage:(CGImageRef)CGImage
引数に指定されたQuartzイメージでオブジェクトを初期化
例)UIImage *image = [[UIImage alloc] initWithCGImage:cgImage];

initWithContentsOfFile:
 - (id)initWithContentsOfFile:(NSString *)path
引数で指定したファイルパスのイメージをロードし、オブジェクトを初期化
例)UIImage *image = [UIImage initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"hoge" ofType:@"png"]];

initWithData:
 - (id)initWithData:(NSData *)data
引数で指定したイメージデータを使用し、オブジェクトを初期化
例)UIImage *image = [UIImage initWithData: imageData];
最終更新:2013年02月27日 16:10