2009-08-20 52 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