2010-12-13 35 views
1

我用下面的代码来旋转的UIImage旋转的UIImage并没有显示

double angle = -90; 
NSData *imageData = [NSData dataWithContentsOfFile:sss]; 
UIImage *image =[UIImage imageWithData:imageData]; 
CGSize s = {image.size.width, image.size.height}; 
UIGraphicsBeginImageContext(s); 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextTranslateCTM(ctx, 0,image.size.height); 
CGContextScaleCTM(ctx, 1.0, -1.0); 
CGContextRotateCTM(ctx, 2*M_PI*angle/360); 
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage); 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
[myUIImageView setImage:newImage]; 

,但没有显示在myUIImageView。

如果有什么问题?

欢迎任何评论

感谢

InterDev中

回答

2

如果你将要旋转图像90度,当你创建图像内容,你应该换的宽度和高度:

CGSize s = {image.size.height, image.size.width}; 

这样,就有足够的空间来绘制完全变换的图像。尝试将图像绘制成超出图形上下文边界的矩形将导致不绘制任何内容。

P.S.我建议使用CGBitmapContext而不是UIGraphicsBeginImageContext(),因为前者是线程安全的,这意味着如果您愿意,您可以在后台线程上对图像进行操作。

+0

是的,我想绘制一个旋转的图像矩形,如何显示所有旋转的图像? – arachide 2010-12-13 08:30:13

+0

我得到了解决方案!谢谢 – arachide 2010-12-13 09:35:01