1

我正在使用 NSAffineTransform 来旋转/反映 NSImage,当使用更大的图像时,我遇到了错误:

NSImage: Insufficient memory to allocate pixel data buffer of 4496342739800064 bytes

我在这里转换的图像是 6,998,487 字节,大小为 4110px x 2735。NSAffineTransform 真的需要这么多内存来进行这种转换,还是我在某个地方出错了?这是我的旋转代码:

-(NSImage *)rotateLeft:(NSImage *)img{
    NSImage *existingImage = img;
    NSSize existingSize;


    existingSize.width = existingImage.size.width;
    existingSize.height = existingImage.size.height;

    NSSize newSize = NSMakeSize(existingSize.height, existingSize.width);
    NSImage *rotatedImage = [[NSImage alloc] initWithSize:newSize];

    [rotatedImage lockFocus];


    NSAffineTransform *rotateTF = [NSAffineTransform transform];
    NSPoint centerPoint = NSMakePoint(newSize.width / 2, newSize.height / 2);

    [rotateTF translateXBy: centerPoint.x yBy: centerPoint.y];
    [rotateTF rotateByDegrees: 90];
    [rotateTF translateXBy: -centerPoint.y yBy: -centerPoint.x];
    [rotateTF concat];

    NSRect r1 = NSMakeRect(0, 0, newSize.height, newSize.width);
    [existingImage drawAtPoint:NSMakePoint(0,0)
        fromRect:r1
       operation:NSCompositeCopy fraction:1.0];

    [rotatedImage unlockFocus];

    return rotatedImage;
}

我在我的项目中使用 ARC。在此先感谢,本

4

0 回答 0