2009-08-20 50 views
0

我有一个程序可以打开TIFF文档并显示它们。我正在使用setFlipped:YES。NSBitmapImageRep和多页面TIFFs

如果我只是在处理单页图像文件,我可以做

[image setFlipped: YES]; 

而且,除了视图被翻转,似乎正确地绘制图像。

但是,由于某些原因,设置图像的翻转似乎不会影响各个表示的翻转。

这是相关的,因为多页TIFF的多个图像看起来像是同一图像的不同“表示”。所以,如果我只是绘制图像,它会翻转,但如果我绘制一个特定的表示,它不会翻转。我也似乎无法弄清楚如何选择哪种表示法是绘制NSImage时绘制的默认表示法。

谢谢。

回答

0

我认为答案是,是的,不同的页面是分开的陈述,以及对付他们正确的做法是把它们变成图片提供:

NSImage *im = [[NSImage alloc] initWithData:[representation TIFFRepresentation]]; 
[im setFlipped:YES]; 
1

你不应该使用-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 
+0

这是第一个技术我试过了,但由于某些原因,该转换只得到了第一次执行我画的形象,所以当我重新大小的窗口,图像变得颠倒了...... – 2009-08-27 14:08:39