0

I wanted to rotate the contents of the CGContextRef with -90 degrees. I found some code but it is not working correctly.

CGContextRef tempColorRef = CGBitmapContextCreate(NULL, width, height, bitsPerComponent,
                                                  bytesPerRow, colorspace,
                                                  kCGImageAlphaPremultipliedLast);
CGImageRef colorImageRef = CGBitmapContextCreateImage(colorContextRef);
CGContextTranslateCTM(tempLayerRef, width / 2, height / 2);
CGContextRotateCTM(tempLayerRef, DegreesToRadians(-90));
CGContextScaleCTM(tempColorRef, 1.0, -1.0);
CGContextDrawImage(tempColorRef, CGRectMake(-width / 2, -height / 2, width, height), colorImageRef);
CGImageRelease(colorImageRef);

colorContextRef = tempColorRef;

Anyone help me please.

Jun
  • 3,422
  • 3
  • 28
  • 58
  • 2
    What does "not working correctly" mean? Do you experience nasal demons or what? –  Sep 22 '12 at 08:30
  • The contents have disappeared. – Jun Sep 22 '12 at 10:11
  • I'm sure the math part is screwed up and you're drawing *outside* the context. What if you remove the scale part? –  Sep 22 '12 at 10:13

1 Answers1

0

According to the H2CO3's comments, I tried various transformations.

It was my fault. width and height were size_t variables, so these can't hold minus values. The error was happening in the following instruction.

CGRectMake(-width / 2, -height / 2, width, height)

It's working fine now.

Jun
  • 3,422
  • 3
  • 28
  • 58