gpt4 book ai didi

ios - iOS:使用CGContextRotate旋转

转载 作者:行者123 更新时间:2023-12-01 19:19:32 25 4
gpt4 key购买 nike

我正在尝试旋转图像,我想在图像文件上绘制(到上下文)。
一切正常,除非我旋转图像。

基本上我有一个形象。我想缩放和调整图像的大小,然后将其裁剪为矩形,最后将其绘制到UICurrentContext上;

//create a new graphic context
UIGraphicsBeginImageContext(CGSizeMake(500, 500));
CGContextRef graphicContext = UIGraphicsGetCurrentContext();
CGContextDrawImage(graphicContext, CGRectMake(0, 0, rect.size.width, rect.size.height), image.CGImage);
CGContextRotateCTM(graphicContext, 45 * M_PI/180.0);
UIImage* editedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//draw it to the current context
[editedImage drawAtPoint:CGPointMake(0,0)];

问题是当我旋转图像时,我不知道imagecontext的新大小是多少。紧接着,已编辑图像中的图像被 而不是旋转。

最佳答案

在绘制之前,您需要旋转上下文。我知道这似乎很愚蠢,但是使用一张纸的类比……这是一张无法移动的纸。取而代之的是,您必须围绕它移动,然后绘制。

这样,您的大小就不会改变,因为任何太大的东西都将被切断。

编辑另外,此函数采用弧度而不是度,因此您无需像执行时那样进行转换。如果要45度,则将是PI / 4(在math.h中存储为常量M_PI_4)。

关于ios - iOS:使用CGContextRotate旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11011425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com