NSImage:initByReferencingFile:
Home 目次>ApplicationKit>NSImage

initByReferencingFile:

ファイル名でNSImageを作って初期化して返す


-(id) initByReferencingFile:(NSString *)filename


【返り値】
   id画像
【パラメータ】
   filename画像ファイル名


【解説】

ファイル名で画像(NSImage)を作って初期化して返します。
実際に画像を使うまでは読み込んだりしません。
ファイル名は拡張子を含む絶対パス、または相対パスです。
初期設定で扱うことの出来るファイル形式はTIFF,GIF,jpg,pdf.pict,epsです。
初期化できなければnilを返します。



【例文】


@implementation SetImage

- (IBAction)set:(id)sender
{
//開けるファイル拡張子の配列
NSArray *imgTypes = [ NSArray arrayWithObject : @"tiff" ];
//OpenPanelを作る
NSOpenPanel *opImage = [ NSOpenPanel openPanel ];
//Imageを作る
NSImage *img;
//OpenPanelの結果のボタン番号
int opRet;

//OpenPanelでファイル選択
opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
file : @"Pictures" //どのどのファイルを選択しておくか
types : imgTypes ];//選べるファイルタイプ

if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら
//NSImageを作ってファイルから読み込む
img = [ [ NSImage alloc ]
initByReferencingFile: [ opImage filename ] ];


//レシーバimage(NSImageView)にimgをセットする
[image setImage : img ];
}
}

@end


(C) 2000-2007 Satoshi Oomori.
[Apple]

Google
Webwww.oomori.com
Apple_Store_40x120

[ad:Usual day in Japan]

この記事を評価してください。 

良い 

間違いがある 説明がわかりにくい 例文がわかりにくい  

Home 目次>ApplicationKit>NSImage
修正日2006.12.26