NSBitmapImageRep和多页TIFF
-
19-09-2019 - |
题
我有一个程序,可以打开TIFF文档并显示它们。我使用setFlipped:YES。
如果我只是在处理单页图像文件,我可以做
[image setFlipped: YES];
和的是,除了被翻转视图,似乎正常绘制图像。
然而,由于某种原因,设置翻转的图像似乎不影响个体表示的flippedness。
这是相关的,因为一个多页的TIFF的多个图像似乎表现为不同的同一图像的“表示”。所以,如果我只是绘制图像,它的翻转,但如果我画一个具体表现,它不是翻转。我也似乎无法弄清楚如何选择其代表是当你画的是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