| Home 目次>ApplicationKit>NSImage | |
isValid
画像の内容があるかを返します
-(BOOL) isValid
【返り値】 | |
| BOOL | YES/NO |
【解説】
画像の内容があるかを返します。
【例文】
#import "SetImage.h"
@implementation SetImage
- (IBAction)set:(id)sender
{
//開けるファイル拡張子の配列
NSArray *imgTypes = [ NSArray arrayWithObject : @"tiff" ];
//OpenPanelを作る
NSOpenPanel *opImage = [ NSOpenPanel openPanel ];
//OpenPanelの結果のボタン番号
int opRet;
NSImageRep *imgRep;
NSImage *img=[[NSImage allocWithZone:[self zone]] initWithSize:NSMakeSize(100,100)];
//OpenPanelでファイル選択
opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
file : @"Pictures" //どのどのファイルを選択しておくか
types : imgTypes ];//選べるファイルタイプ
if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら
imgRep = [NSImageRep imageRepWithContentsOfFile:[ opImage filename ]];
[img addRepresentation:imgRep];
if ([img isValid]){
NSLog(@"YES");
}else{
NSLog(@"NO");
}
[image setImage:img];
}
}
@end
![]() | |
この記事を評価してください。
| Home 目次>ApplicationKit>NSImage | 修正日2006.12.26 |