谁能告诉我怎样才能得到NSImage的真实宽度和高度?我注意到DPI高于72的图像在NSImage.size参数中的宽度和高度不准确。
我在Cocoadev上看到了这个例子:
NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];
NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);然而,bestRepresentationForDevice在10.6中已被弃用...我可以使用什么作为替代,文档没有提供不同的方法?
发布于 2011-01-21 00:58:26
从NSImage的TIFF表示构建NSBitmapImageRep
NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];发布于 2012-05-17 04:27:19
遍历图像的表示,查找具有最大-size的图像。调用-bestRepresentationForRect:context:hints:如果你输入一个非常大的矩形,应该可以帮你做到这一点。
发布于 2012-05-15 20:36:28
@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;
}
@endhttps://stackoverflow.com/questions/4748846
复制相似问题