6

Retina ディスプレイで作業しているときに問題が発生しました。NSImage のサイズは正しいですが、そこから NSBitmapImageRep を作成してファイルに書き込むと、画像の魔女のサイズが元の画像の 2 倍になります。非Retinaディスプレイで使用する場合、そのような問題はありません。

  • ファイル (1920x1080) から NSImage を作成します
  • 私はいくつかの絵を描きます
  • 描画付きの画像から NSBitmapImageRep を作成します
  • ファイルに書き込みます
  • 3840x2160 の寸法の画像を取得します

何が原因でしょうか?


NSImage *originalImage = [[NSImage alloc] initWithContentsOfURL:fileUrl];

NSImage *editedImage = [[NSImage alloc] initWithSize:originalImage.size];

[editedImage lockFocus];
//I draw here NSBezierPaths
[editedImage unlockFocus];

NSBitmapImageRep *savingRep = [NSBitmapImageRep imageRepsWithData:[editedImage TIFFRepresentation]];
NSData *savingData = [savingRep representationUsingType: NSPNGFileType properties: nil];
[savingData writeToFile:desiredFileLocationAndName atomically:no];

画像を開いて編集せずに保存すると、正しい寸法の画像が得られます

NSImage *imageFromFile = [[NSImage alloc] initWithContentsOfURL:fileURL];
NSBitmapImageRep *newRepresentation = [[NSBitmapImageRep imageRepsWithData:[imageFromFile TIFFRepresentation]];
NSData *savingData = [newRepresentation representationUsingType: NSPNGFileType properties: nil];
[savingData writeToFile:desiredFileLocationAndName atomically:no];
4

1 に答える 1

1

イメージのビットマップ表現は、ピクセル単位で測定されます。2倍の大きさですNSImage は、Retina デバイスでポイントあたり 2 ピクセルを測定するポイントのサイズを示しています。それがあなたに与えるものに何の問題もありません。

于 2013-03-19T13:25:39.130 に答える