我的目标是在视图中显示图像。考虑到我有一个:
- IBOutlet NSImageView *image 用于显示我的图像
- NSData *imageData 用于读取图像文件
- NSImage *imageView
在 imageData 中存储图像(我使用了 initWithContentsOfFile 方法)。
现在,如果我使用以下命令初始化 imageView:
NSImage *imageView = [[NSImage alloc] initWithContentsOfFile:path];
我可以正确地看到图像的渲染,但是通过这种方式我从文件系统中读取了两次。
如果我尝试:
NSImage *imageView = [[NSImage alloc] initWithData:imageData];
显示的图像非常小..像拇指
Whit CGImageRef:
CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
CGImageRef imageRef= CGImageSourceCreateImageAtIndex(imageSource, 0, nil);
NSImage *imageView = [[NSImage alloc] initWithCGImage:imageRef size:NSZeroSize];
图像仍然渲染得太小。
如何以原始分辨率显示图像?