Rotating an image context (CGContextRotateCTM) causing it to become blank. Why?

前端 未结 5 1180
一生所求
一生所求 2020-12-05 00:23
#define radians(degrees) (degrees * M_PI/180)

UIImage *rotate(UIImage *image) {
  CGSize size = image.size;;

  UIGraphicsBeginImageContext(size);
  CGContextRef co         


        
5条回答
  •  死守一世寂寞
    2020-12-05 00:54

    If you don't want to change all the origins and sizes, move the center, rotate and change the center to corner again like this:

    CGContextTranslateCTM( context, 0.5f * size.width, 0.5f * size.height ) ; CGContextRotateCTM( context, radians( 90 ) ) ; CGContextTranslateCTM( context, -0.5f * size.width, -0.5f * size.height ) ;

    Then draw normally like this:

    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

提交回复
热议问题