NSImage -drawAtPoint:画得太小

时间:2012-12-24 10:38:54

标签: image macos cocoa merge

我用这个来结合2个NSImages:

newImage = [[NSImage alloc] initWithSize:NSMakeSize(size1.width,
                                                    size1.height + size2.height)];
[newImage lockFocus];
[firimage drawAtPoint:NSMakePoint(0, 0)
             fromRect:NSMakeRect(0, 0, size1.width, size1.height)
            operation:NSCompositeSourceOver
             fraction:1.0];
[secimage drawAtPoint:NSMakePoint(0, size1.height)
             fromRect:NSMakeRect(0, 0, size2.width, size2.height)
            operation:NSCompositeSourceOver
             fraction:1.0];
[newImage unlockFocus];

它会产生尺寸合适的图像(2 100x63图像会产生100x126图像),但是两个单独的图像绘制得太小,因此生成的图像大部分都是空白的:

Screenshot

以下是原始图片:

Image 1 Image 2

2 个答案:

答案 0 :(得分:1)

我看到你解决了。在使用您的代码时,我得到了类似的奇怪结果。所以我开始认为我并不是真的了解这些方法。

我通常总是使用-drawInRect:fromRect:operation:fraction,虽然我不是100%这两个因素对结果的影响,但我总是得到我需要的结果。

无论如何,我离开并制作了一个小玩具应用程序,以显示交互式修改rects的效果(根据您的问题使用两个图像)。

I've put it up on github,你可能想看看。

答案 1 :(得分:0)

正如我在评论中所说,使用-drawInRect:fromRect:operation:fraction解决了这个问题!