我有一个可以打开TIFF文档并显示它们的程序。我使用的是setFlipped:是。
如果我只处理单页图像文件,我可以
[image setFlipped: YES];而且,除了视图被翻转之外,似乎还可以正确地绘制图像。
但是,由于某些原因,设置图像的翻转似乎不会影响各个表示的翻转。
这是相关的,因为多页TIFF的多个图像似乎显示为同一图像的不同“表示”。所以,如果我只是画图像,它是翻转的,但如果我画一个特定的表示,它不会翻转。我似乎也不知道如何选择在绘制NSImage时绘制的默认表示形式。
谢谢。
发布于 2009-08-21 14:30:49
我相信答案是肯定的,不同的页面是独立的表示,处理它们的正确方法是将它们变成图像,如下所示:
NSImage *im = [[NSImage alloc] initWithData:[representation TIFFRepresentation]];
[im setFlipped:YES];发布于 2009-08-27 09:44:20
您不应该使用-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];
}
@endhttps://stackoverflow.com/questions/1308745
复制相似问题