0

在下面的代码中,img不是转换后的图像。如何转换图像?

 CGAffineTransform transform = self.imageView.transform;

 if(transform.a == 1)
 {    
     transform.a = -1;
 }
 else
 {     
     transform.a = 1;   
 }

 self.imageView.transform = transform;

 UIImage *img = self.imageView.image;

这是图像:

在此处输入图像描述

转换后,它应该如下所示:

在此处输入图像描述

4

2 回答 2

1

我认为你以错误的方式接近它。像这样的东西应该工作:

UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];
UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
于 2013-06-19T15:16:22.370 回答
0

变换应用于视图,而不是图像。如果您想要应用了变换的图像,则需要将图像视图渲染为新图像。谷歌“将 uiview 绘制到 uiimage”或https://stackoverflow.com/search?q=draw+uiview+into+uiimage

于 2013-06-19T14:33:07.883 回答