3

NSImage の実​​際の幅と高さを取得する方法を教えてもらえますか? DPI が 72 よりも高い画像は、NSImage.size パラメーターを使用すると幅と高さが不正確になることに気付きました。

Cocoadev でこの例を見ました:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];

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

ただし、 bestRepresentationForDevice は 10.6 で廃止されました...代わりに何を使用できますか?ドキュメントには別の方法が記載されていませんか?

4

3 に答える 3

4

NSImage の TIFF 表現から NSBitmapImageRep を構築します

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
于 2011-01-20T16:58:25.880 に答える
1

画像の表現を繰り返して、サイズが最大のものを探します。-bestRepresentationForRect:context:hints:を呼び出すと、非常に大きな長方形をフィードする場合にこれを行う必要があります。

于 2012-05-16T20:27:19.197 に答える
0
@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
于 2012-05-15T12:36:27.823 に答える