我想选择一个带有浏览窗口的图像并很好地放入图像。
这是我的代码,我可以选择图像但看不到图像,选择后它应该很好地出现在窗口上的图像中。
- (IBAction)chooseImage:(id)sender
{
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setPrompt:@"Select"];
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:YES];
if ( [openDlg runModal] == NSOKButton )
{
NSArray* files = [openDlg URLs];
// Loop through all the files and process them.
for( int i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
NSImage *iconImage=[[NSImage alloc] initWithContentsOfFile:fileName];
[imageView setImage:iconImage];
}
}
}
在界面生成器中,我已将浏览按钮与
- (IBAction)chooseImage:(id)sender;
和图像井对象
@property (assign) IBOutlet NSImageView* imageView;
谢谢