【发布时间】:2011-03-14 13:47:23
【问题描述】:
我的目标是在视图中显示图像。 考虑到我有:
- IBOutlet NSImageView *用于显示我的图像的图像
- NSData *imageData 用于读取图像文件
- NSImage *imageView
在 imageData 中存储图像(我使用了 initWithContentsOfFile 方法)。
现在,如果我使用以下命令初始化 imageView:
NSImage *imageView = [[NSImage alloc] initWithContentsOfFile:path];
我可以正确看到图像的渲染,但是这样我从文件系统中读取了两次。
如果我尝试:
NSImage *imageView = [[NSImage alloc] initWithData:imageData];
显示的图像非常小..像拇指
惠特 CGImageRef:
CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
CGImageRef imageRef= CGImageSourceCreateImageAtIndex(imageSource, 0, nil);
NSImage *imageView = [[NSImage alloc] initWithCGImage:imageRef size:NSZeroSize];
图像仍然渲染得太小。
如何以原始分辨率显示图像?
【问题讨论】:
-
如果
initWithContentsOfFile:适用于NSImage,为什么还需要NSData? (但我同意这很奇怪——可能是图像表示或尺寸问题。) -
我已经编辑了我的帖子:添加了 imageSource
-
我有一个用于读取 exif 标签的 NSData。
-
@Joe Blow:我不认为改变 dpi 可能是解决方案。原始分辨率约为2800x1300,结果约为100x70。
-
我想我只得到一个拇指而不是完整的图像..但我不知道如何检索存储真实图像的 NSData 部分。
标签: objective-c nsview nsdata nsimage cgimage