百度空间 | 百度首页 
 
查看文章
 
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];

类别:默认分类 | 浏览() | 评论 (0)
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu