2012-07-05 3 views
5

は、ここに私のコードですはNSImageでは、私はNSImageでは上の十字架を追加したい網膜ディスプレイ混乱

2012-07-06 00:53:09.889 RetinaTest[8074:403] backingScaleFactor : 1.000000 
2012-07-06 00:53:09.901 RetinaTest[8074:403] imgPixelSize.width: 515.000000 , imgPixelSize.height:600.000000 
2012-07-06 00:53:09.902 RetinaTest[8074:403] imgPointSize.width: 515.000000 , imgPointSize.height:600.000000 

しかし網膜ディスプレイ(私は実際の網膜ディスプレイを使用していませんが、ヒディピモード): enter image description here

コンソール:

2012-07-06 00:56:05.071 RetinaTest[8113:403] backingScaleFactor : 2.000000 
2012-07-06 00:56:05.083 RetinaTest[8113:403] imgPixelSize.width: 515.000000 , imgPixelSize.height:600.000000 
2012-07-06 00:56:05.084 RetinaTest[8113:403] imgPointSize.width: 257.500000 , imgPointSize.height:300.000000 

私はこれらの行を省略した場合:

NSAffineTransform *trans = [[[NSAffineTransform alloc] init] autorelease]; 
      [trans scaleBy:1.0/scale]; 
      [trans set]; 

enter image description here

を私は[NSAffineTransform SCALEBY]を1.0に変更した場合しかし、結果は

NSAffineTransform *trans = [[[NSAffineTransform alloc] init] autorelease]; 
     [trans scaleBy:1.0]; 
     [trans set]; 
権利であります

enter image description here

コンソール:

2012-07-06 01:01:03.420 RetinaTest[8126:403] backingScaleFactor : 2.000000 
2012-07-06 01:01:03.431 RetinaTest[8126:403] imgPixelSize.width: 515.000000 , imgPixelSize.height:600.000000 
2012-07-06 01:01:03.432 RetinaTest[8126:403] imgPointSize.width: 257.500000 , imgPointSize.height:300.000000 

は誰が説明を与えることができるしてください?網膜ディスプレイとは違う奇形モードですか?

答えて

4

私は答えを見つけたと思います。 NSAffineTransformがNSImageのコンテキストに設定されている場合、座標系はピクセルの次元に変換されます。これは2 xの点の次元です。たとえそれが空の場合でも:

NSAffineTransform *trans = [[[NSAffineTransform alloc] init] autorelease]; 
[trans set]; 

私はそれがバグかどうかは分かりませんが、それは動作します。

0

変換をリセットすることはバグではありません(自分の答えを参照)。 hidpiを使用すると、デフォルトの変換は、ほとんどの高水準コードがそのまま動作するようになります。アイデンティティ変換にリセットすると、これを元に戻して座標系1:1をピクセルに揃えます。

これはほとんど必要ありません。これは、行を除いて動作するはず

NSImage *img = [[[NSImage alloc]initWithContentsOfFile:@"/Users/support/Pictures/cat.JPG"] autorelease]; 
NSSize size = img.size; 

NSBezierPath *path = [NSBezierPath bezierPath];  
[[NSColor redColor] setStroke]; 
[path moveToPoint:NSMakePoint(0.0, 0.0)]; 
[path lineToPoint:NSMakePoint(size.width, size.height)]; 
[path moveToPoint:NSMakePoint(0.0, size.height)]; 
[path lineToPoint:NSMakePoint(size.width, 0.0)]; 

[path setLineWidth:1]; 
[path stroke]; 
[img unlockFocus]; 

[imageView setImage:img]; 
... 

ではなく、広い2つの物理的なピクセルである(しかし、もちろん、通常の画像に類似の幅になります。画像担当者や変換の変更を取るためにあなたのコードを簡素化することは、あなたがこれを取得できます画面)。この簡単な特別なケースを試してみてください:

[path setLineWidth:(img.scale > 1) ? 0.5 : 1.0]; 
関連する問題