0

In the code below, img is not a transformed image. How do I transform the image?

 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;

This is the image:

enter image description here

After the transform, it should look like this:

enter image description here

woz
  • 10,888
  • 3
  • 34
  • 64

2 Answers2

1

I think you are approaching it the wrong way. Something like this should work:

UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];
UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
woz
  • 10,888
  • 3
  • 34
  • 64
  • u can see the image before transform through this link.....http://sphotos-a.ak.fbcdn.net/hphotos-ak-frc3/q71/988639_192688244227063_1733135779_n.jpg /n and u can see the image after transform through this link.....http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash4/q71/998366_192685424227345_883357333_n.jpg – Vikas Gupta Jun 19 '13 at 15:27
  • Yes, I added that to your question. Does the code I posted help you at all? – woz Jun 19 '13 at 15:28
  • Cheeky :) you should really check the existing orientation of the image before setting the new orientation... – Wain Jun 19 '13 at 15:32
0

The transform is applied to the view, not the image. If you want an image with the transform applied you need to render the image view into a new image. Google "draw uiview into uiimage" or https://stackoverflow.com/search?q=draw+uiview+into+uiimage.

Community
  • 1
  • 1
Wain
  • 118,658
  • 15
  • 128
  • 151
  • CGAffineTransform transform = self.imageView.transform; – Vikas Gupta Jun 19 '13 at 14:42
  • this is used for transform the image if we transform then how we get the tranform image – Vikas Gupta Jun 19 '13 at 14:42
  • That is used to transform the view, which results in a change to the image ON SCREEN, but not in memory. To get the transformed image as a new image you need to draw the view into a new image. There are many posts on how to do that. Like http://stackoverflow.com/questions/3129352/need-to-capture-uiview-into-a-uiimage-including-all-subviews – Wain Jun 19 '13 at 14:44
  • how i post a image to you then u can understand my question.....i want to show you a example – Vikas Gupta Jun 19 '13 at 14:53
  • You can upload an image somewhere and add a link to it here – Wain Jun 19 '13 at 14:59
  • http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash4/q71/998366_192685424227345_883357333_n.jpg – Vikas Gupta Jun 19 '13 at 15:04
  • image before transform – Vikas Gupta Jun 19 '13 at 15:04
  • image after transform ......http://sphotos-a.ak.fbcdn.net/hphotos-ak-frc3/q71/988639_192688244227063_1733135779_n.jpg – Vikas Gupta Jun 19 '13 at 15:07
  • u can see the image before transform through this link.....http://sphotos-a.ak.fbcdn.net/hphotos-ak-frc3/q71/988639_192688244227063_1733135779_n.jpg – Vikas Gupta Jun 19 '13 at 15:25
  • So do you really need the image? Or you should just add the transformed image view to the screen and it will work? – Wain Jun 19 '13 at 15:33
  • i need a image after transform... – Vikas Gupta Jun 19 '13 at 15:48