NSImage DPI 问题

发布于 2024-10-13 04:41:01 字数 349 浏览 6 评论 0原文

谁能告诉我如何获得 NSImage 的真实宽度和高度?我注意到 DPI 高于 72 的图像的 NSImage.size 参数的宽度和高度不准确。

我在 Cocoadev 上看到了这个例子:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];

NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);

然而 bestRepresentationForDevice 在 10.6 上已被弃用...我可以使用什么作为替代方法,文档没有提供不同的方法?

Can anyone tell me how I can get the true width and height of an NSImage? I have noticed that images that are a higher DPI than 72 come through with inaccurate width and height with the NSImage.size parameters.

I saw this example on Cocoadev:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];

NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);

However bestRepresentationForDevice is deprecated on 10.6... what can I use as an alternative, the documentation doesn't offer a different method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猛虎独行 2024-10-20 04:41:01

从 NSImage 的 TIFF 表示构建 NSBitmapImageRep

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];

Build your NSBitmapImageRep from the TIFF representation of the NSImage

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
只有一腔孤勇 2024-10-20 04:41:01

迭代图像的表示,寻找具有最大 -size 的图像。如果您提供一个非常大的矩形,则调用 -bestRepresentationForRect:context:hints: 应该会为您完成此操作。

Iterate through the image's representation looking for the one with the largest -size. Calling -bestRepresentationForRect:context:hints: should do this for you if you feed an extremely large rectangle.

花海 2024-10-20 04:41:01
@interface NSImage (Representation)
-(NSBitmapImageRep*)bitmapRepresentation;
@end

@implementation NSImage (Representation)
-(NSBitmapImageRep*)bitmapRepresentation {
    for (id thing in self.representations) {
        if (![thing isKindOfClass:[NSBitmapImageRep class]]) continue;
        return (NSBitmapImageRep*)thing;
    }
    return nil;
}
@end
@interface NSImage (Representation)
-(NSBitmapImageRep*)bitmapRepresentation;
@end

@implementation NSImage (Representation)
-(NSBitmapImageRep*)bitmapRepresentation {
    for (id thing in self.representations) {
        if (![thing isKindOfClass:[NSBitmapImageRep class]]) continue;
        return (NSBitmapImageRep*)thing;
    }
    return nil;
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文