UIImage Rotation custom degrees

后端 未结 1 1341
时光说笑
时光说笑 2020-12-05 06:04

I have been using the code in this sample to assist and this works well. http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

I cannot

相关标签:
1条回答
  • 2020-12-05 06:26

    You'll want to do pretty much the same stuff as in that post does in rotate:

    CGSize size = sizeOfImage;
    UIGraphicsBeginImageContext(size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextRotateCTM(ctx, angleInRadians);
    CGContextDrawImage(ctx, (CGRect){{}, size}, image);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
    

    You might need to also translate the CTM in addition to rotating to compensate for the center of rotation. If you want to not crop the edges of the image when rotating, you should increase the size with some basic trig.

    0 讨论(0)
提交回复
热议问题