1

I'm trying to draw an image to the screen in a UIView subclass I'm making.

It's all working perfectly expect for the fact that my image is coming out upside down.

I'm using the code...

CGFloat height = CGRectGetHeight(rect);
CGFloat width = CGRectGetWidth(rect);
UIImage *thumbImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"single_blue" ofType:@"png"]];
CGImageRef thumbImageRef = thumbImage.CGImage;
CGContextDrawImage(context, CGRectMake((width/10)*[mean doubleValue] - 13, -3, 26, 35), thumbImageRef);

Any ideas why it's coming out upside down?

Thanks for any help.

Oliver

::EDIT:: OK, so Safari looks like it's died. Chrome is working fine though. Very odd.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage See here for fix. Safari died and broke Stack Overflow so I couldn't search. All better now though and found this :D – Fogmeister Aug 26 '10 at 22:28

1 Answers1

2

The iPhone CoreGraphics coordinate system is flipped upside-down from that of the Mac. I often just vertically preflip all my images before adding them to my iPhone projects.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153