2011-01-20 9 views
3

NSImageの実際の幅と高さをどのように得ることができますか?私は、72よりも高いDPIである画像が、NSImage.sizeパラメータで不正確な幅と高さを持つことに気付きました。NSImage DPI質問

私はCocoadevにこの例を見ました:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil]; 

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

しかしbestRepresentationForDeviceは10.6で廃止されました...私は代替として何を使用することができ、ドキュメントには、別の方法を提供していませんか?

答えて

4

最大-sizeと1を探している画像の表現を通してNSImageでは

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

作品!よかった。ありがとう – mootymoots

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 
1

反復のTIFF表現から、あなたのNSBitmapImageRepをビルドします。 -bestRepresentationForRectを呼び出す:context:hints:非常に大きな矩形を送る場合は、これを行う必要があります。