-initWithContentsOfURL:
URLで指定したファイルのデータを読んで、データオブジェクトを初期化して返します
-(id)initWithContentsOfURL:(NSURL *)anURL
解説
URLで指定したファイルのデータを読んで、データオブジェクトを初期化して返します。
フレームワーク
Foundation
クラス
NSData
使用可能
10.0
参照
関連記事(外部サイト)
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //Imageを作る NSImage *img = [[[NSImage alloc] initWithSize:NSMakeSize(100,100)] autorelease]; NSBitmapImageRep *bmpRep; NSData *dat; NSURL *url = [NSURL URLWithString:@"http://www.oomori.com/image/oomoricom.png"]; dat = [[NSData alloc] initWithContentsOfURL: url ]; bmpRep = [NSBitmapImageRep imageRepWithData:dat]; [img addRepresentation:bmpRep]; [image setImage:img]; NSLog([NSString stringWithFormat:@"bit / pixel:%d",[bmpRep bitsPerPixel]]); } @end