代码之家  ›  专栏  ›  技术社区  ›  Alan

uiImageView:旋转和缩放。如何保存结果?

  •  0
  • Alan  · 技术社区  · 15 年前

    我正在尝试在用户编辑的位置和缩放比例中将旋转和缩放的uiImageView保存为uiImage。但是我只能像编辑之前那样保存原始图像。如何以相同的缩放和旋转保存uiImageView中显示的图像?我已经读到我需要使用uigraphicsgetcurrentContext(),但是我得到了相同的原始图像保存(但翻转),而不是旋转的图像!!建议和提示非常有用。 提前谢谢。 铝

    (UIImage *)getImage
    {
    CGSize size = CGSizeMake(250, 250);
    UIGraphicsBeginImageContext(size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGMutablePathRef path = CGPathCreateMutable();
    
    // Add circle to path
    CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, 250, 250));
    CGContextAddPath(context, path);
    
    // ****************** touchImageView is my UIImageView ****************//
    CGContextDrawImage(context, CGRectMake(0, 0, 250, 250), [touchImageView image].CGImage);
    
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // Clip to the circle and draw the logo
    CGContextClip(context);
    UIGraphicsEndImageContext();
    
    return scaledImage;
    

    }

    2 回复  |  直到 14 年前
        1
  •  1
  •   Ken Aspeslagh    15 年前

    我在你发布的代码中没有看到任何可以旋转图像的内容。你忘了加吗?

    看来你走对了。现在您应该使用转换例程 CGContextScaleCTM CGContextRotateCTM 要适当地修改变换矩阵,然后(为了避免翻转),请使用 -[UIImage drawAtPoint:] 绘制ui图像而不是使用 CGContextDrawImage .

        2
  •  1
  •   TechZen    15 年前

    基于视图的转换应用于上下文的输出,而不是上下文本身。我相信你必须使用 link text 核心图形的特定功能。

    (我可能错了。我不记得我以前是怎么做到的,拿着这个加一粒盐。)