2010-05-04 81 views
1

這是我drawInContext方法:爲什麼我的形象是顛倒了?

UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]]; 
CGRect cropRect = CGRectMake(0, 0, 175, 175); 
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect); 

CGRect imageRect; 

imageRect.origin = CGPointMake(0, 0); 
imageRect.size = CGSizeMake(175, 175); 

CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef); 
CGImageRelease(imageRef); 

我的形象是顛倒的,我該怎麼改變呢?我的代碼有什麼問題?我怎樣才能改變圖像變得正常?謝謝 。

+0

http://stackoverflow.com/questions/506622/cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage – 2010-05-04 13:14:01

回答

2

取而代之的是:

CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, imageRef); 

做到這一點:

[img drawInRect:CGRectMake(0, 0, 175, 175)] 

CGContextDrawImage不保留方向。

相關問題