NSBitmapImageRep 和多页 TIFF

发布于 2024-08-03 07:38:23 字数 332 浏览 7 评论 0原文

我有一个可以打开 TIFF 文档并显示它们的程序。我正在使用 setFlipped:YES。

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

[image setFlipped: YES];

这样做,除了翻转视图之外,似乎还可以正确绘制图像。

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

这是相关的,因为多页 TIFF 的多个图像似乎显示为同一图像的不同“表示”。因此,如果我只绘制图像,它就会翻转,但如果我绘制特定的表示,它就不会翻转。我似乎也不知道如何选择绘制 NSImage 时绘制的默认表示形式。

谢谢。

I've got a program that can open TIFF documents and display them. I'm using setFlipped:YES.

If I'm just dealing with single page image files, I can do

[image setFlipped: YES];

and that, in addition to the view being flipped, seems to draw the image correctly.

However, for some reason, setting the flipped of the image doesn't seem to affect the flippedness of the individual representations.

This is relevant because the multiple images of a multi-page TIFF seem to appear as different "representations" of the same image. So, if I just draw the IMAGE, it's flipped, but if I draw a specific representation, it isn't flipped. I also can't seem to figure out how to chose which representation is the default one that gets drawn when you draw the NSImage.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柳若烟 2024-08-10 07:38:23

您不应该使用 -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

You shouldn't use the -setFlipped: method to control how the image is drawn. You should use a transform based on the flipped-ness of the context you are drawing into. Something like this (a category on 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
淡淡離愁欲言轉身 2024-08-10 07:38:23

我相信答案是肯定的,不同的页面是单独的表示,处理它们的正确方法是将它们转换为图像:

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

I believe that the answer is that Yes, different pages are separate representations, and the correct way to deal with them is to turn them into images with:

NSImage *im = [[NSImage alloc] initWithData:[representation TIFFRepresentation]];
[im setFlipped:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文