Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

priyank.ranka

macrumors member
Original poster
Jun 11, 2008
51
0
Hi Everyone,
I am writing the code to rotate the image which is an object of UIView class,
but whn i apply transformation it is applied on the entire view object which affects all the images which view object has. Is there any way to rotate only one particular image in the view without affecting other images on the same view..please send your replies as soon as possible

Best Regards,
Priyank Ranka
 
You will need to import the Core Graphics Framework into your project, then use the following code

Code:
nameOfImage.transform = CGAffineTransformMakeRotation(M_PI / 2.0);

That will rotate it 90˚*CW.
 
it gives an error as image itself is an object of UIImage which is been displayed on view.Do you an alternative to this
 
I think the
Code:
transform = CGAffineTransformMakeRotation
requires the CoreGraphics framework, don't forget to add it otherwise you will get an error.
 
When i apply this technique it is apply to the context and not to the image. And image doesnt have transform as the property. When i apply the same logic it gives me an error "transform is something which is not structured".I want to know what type of Object is an image is.
 
Actually i have the following situation..I have two images (let name them as "A" and "B") say for example. It can be either object of UIImage or CGImageRef. Both belong to same view. Now i want to rotate image "A" which is a background image and i want to display image "B" which is small above the image "A".This is the situation. If I create a separate view for image "A" and rotate it by using CGAffineTransformation it will roatate image "A" but you wont be able to display image "B" over image "A".

this is the situation in which i am stuck into.Please help me out so that i can rotate one image and display a static image over it
 
how to rotate an image

Hi Priyank,
What you can do is have UIImageview and add it to ur view.
And thus u can apply rotation to ur UIImageview.
This will solve ur problem :)
 
Hi Suhas, I did the same way but still it didn't solve the problem. The following is the piece of code that I'm using. I'll pass the image as argument to this function.

Code:
- (UIImage *)rotateImage:(UIImage *)image {
	
	int orient = image.imageOrientation;
	
	UIImageView *imageView = [[UIImageView alloc] init];
	
	UIImage *imageCopy = [[UIImage alloc] initWithCGImage:image.CGImage];
	
	switch ([UIDevice currentDevice].orientation) {
		case UIImageOrientationLeft:
			imageView.transform = CGAffineTransformMakeRotation(3 * M_PI / 2.0);
			break;
		case UIImageOrientationRight:
			imageView.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
			break;
		case UIImageOrientationDown: //EXIF = 3
			imageView.transform = CGAffineTransformMakeRotation(M_PI);
		default:
			break;
	}
	
	imageView.image = imageCopy;
	return (imageView.image);
}
 
^ that code has a few issues:

1. The imageOrientation property's type is UIImageOrientation. You should use that instead of int.
2. You are leaking imageView
3. You are leaking imageCopy.
 
^ that code has a few issues:

1. The imageOrientation property's type is UIImageOrientation. You should use that instead of int.
2. You are leaking imageView
3. You are leaking imageCopy.

Also it doesn't rotate anything unless you use imageview to display the image.
 
Also it doesn't rotate anything unless you use imageview to display the image.

That is what I thought, but wasn't sure since I didn't test it.

It'd be better to create a new image and draw the existing image into it with the transform, if you need the rotation saved beyond displaying purposes.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.