canInitWithData:
指定したデータから画像内容オブジェクトを作ることができるかを返します
+(BOOL)canInitWithData:(NSData *)data:
解説
指定したデータ(data)から画像内容オブジェクト(NSImageRep)を作ることができるかを返します。
返り値
( BOOL )
初期化出来たYES/NO
引数
( NSData * )data
データ
フレームワーク
ApplicationKit
クラス
NSImageRep
Class Methods
使用可能
10.0
参照
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObject : @"tiff" ]; //OpenPanelを作る NSOpenPanel *opImage = [ NSOpenPanel openPanel ]; //Imageを作る NSImage *img = [[[NSImage alloc] initWithSize:NSMakeSize(100,100)] autorelease]; NSImageRep *imgRep; NSData *dat; //OpenPanelの結果のボタン番号 int opRet; //OpenPanelでファイル選択 opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのどのファイルを選択しておくか types : imgTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら //NSDataを作ってファイルから読み込む dat = [NSData dataWithContentsOfFile: [ opImage filename ] ]; imgRep = [NSImageRep alloc]; if ([NSImageRep canInitWithData:dat]){ NSLog(@"YES"); }else{ NSLog(@"NO"); } } } @end