NSBitmapImageRepとマルチページTIFFファイル
-
19-09-2019 - |
質問
私は、TIFF形式の文書を開いて、それらを表示することができ、プログラムを持っています。私はsetFlippedを使用しています:YES。
私は1つだけのページの画像ファイルを扱うてる場合は、私が行うことができます。
[image setFlipped: YES];
とそれは、裏返されているビューに加えて、正しく画像を描画するようです。
しかし、何らかの理由で、画像の裏返しを設定すると、個々の表現のflippednessに影響を与えていないようです。
マルチページTIFFの複数の画像は、同じ画像の異なる「表現」として表示されているように見えるので、これが関連しています。だから私はちょうどIMAGEを描く場合は、それが反転していますが、私は特定の表現を描く場合は、それが反転していません。私はまた、あなたがNSImageではを描く際に描かれますデフォルトの一つである表現を選んだする方法を見つけ出すように見えることはできません。
感謝ます。
解決 2
私は答えははい、別のページが別の表現であり、そしてそれらに対処するための正しい方法が持つイメージにそれらを回すためにあるということであると信じています:
NSImage *im = [[NSImage alloc] initWithData:[representation TIFFRepresentation]];
[im setFlipped:YES];
他のヒント
画像を描画する方法を制御する方法:
あなたは-setFlippedを使用しないでください。あなたがに描画されているコンテキストの裏返しネスに基づいた変換を使用する必要があります。このような何か(NSImageでは上のカテゴリ):
@implementation NSImage (FlippedDrawing)
- (void)drawAdjustedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta
{
NSGraphicsContext* context = [NSGraphicsContext currentContext];
BOOL contextIsFlipped = [context isFlipped];
if (contextIsFlipped)
{
NSAffineTransform* transform;
[context saveGraphicsState];
// Flip the coordinate system back.
transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:NSMaxY(dstRect)];
[transform scaleXBy:1 yBy:-1];
[transform concat];
// The transform above places the y-origin right where the image should be drawn.
dstRect.origin.y = 0.0;
}
[self drawInRect:dstRect fromRect:srcRect operation:op fraction:delta];
if (contextIsFlipped)
{
[context restoreGraphicsState];
}
}
- (void)drawAdjustedAtPoint:(NSPoint)point
{
[self drawAdjustedAtPoint:point fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
- (void)drawAdjustedInRect:(NSRect)rect
{
[self drawAdjustedInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
- (void)drawAdjustedAtPoint:(NSPoint)aPoint fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta
{
NSSize size = [self size];
[self drawAdjustedInRect:NSMakeRect(aPoint.x, aPoint.y, size.width, size.height) fromRect:srcRect operation:op fraction:delta];
}
@end
所属していません StackOverflow