查看文章 |
AttachBot update & availiable for Tiger
2009-01-11 23:53
添加了Image Rotation @@ 代码附在后面,注意这种方式旋转.jpg这类有损压缩的图片会有画质的损失。 此外,Port 到Tiger的问题解决了, 主要是自己生成的Setter-Getter没处理好Memory的retain count,所以就Crash了,整个错误非常新手,可惜第一次还是没看出来。还是@property方便,嗯。 NSImage *rotatedImage = [[NSImage alloc] initWithSize:newSize]; [rotatedImage lockFocus]; /** * Apply the following transformations: * * - bring the rotation point to the centre of the image instead of * the default lower, left corner (0,0). * - rotate it by 90 degrees, either clock or counter clockwise. * - re-translate the rotated image back down to the lower left corner * so that it appears in the right place. */ NSAffineTransform *rotateTF = [NSAffineTransform transform]; NSPoint centerPoint = NSMakePoint(newSize.width / 2, newSize.height / 2); BOOL clockwise = YES; [rotateTF translateXBy: centerPoint.x yBy: centerPoint.y]; [rotateTF rotateByDegrees: (clockwise) ? - 90 : 90]; [rotateTF translateXBy: -centerPoint.y yBy: -centerPoint.x]; [rotateTF concat]; /** * We have to get the image representation to do its drawing directly, * because otherwise the stupid NSImage DPI thingie bites us in the butt * again. */ NSRect r1 = NSMakeRect(0, 0, newSize.height, newSize.width); [[image bestRepresentationForDevice: nil] drawInRect: r1]; [rotatedImage unlockFocus]; |