How do I rotate, enlarge UIIMAGES in code?

I have UIIMAGES in my iPhone xcode app.

So I dont have to rotate the images in paint / Gimp
can they be rotated in code? can they be enlarged? what else?


so I can rotate a uiimage to be permanently 90 degrees right? ... twice as big ?
or an arbitrary angle?

beavoidAsked:
Who is Participating?
 
pgnatyukConnect With a Mentor Commented:
I know about CGContextRotateCTM function.

Here are few examples:
 
90 degrees (replace 90 with something else and it will work too):
 http://stackoverflow.com/questions/1315251/how-to-rotate-a-uiimage-90-degrees

Find comment with -(UIImage *)resizeImage:(UIImage *)image function here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/7307-resizing-photo-new-uiimage.html

a clock: http://stackoverflow.com/questions/312226/rotating-two-uiimageviews-360-degrees
0
 
beavoidAuthor Commented:
On this page..

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImage_Class/Reference/Reference.html

What would the line of code look like to flip an image vertically? it isn't clear
0
 
pgnatyukCommented:
There is:
imageWithCGImage:scale:orientation:

orientation
The orientation of the image data. You can use this parameter to specify any rotation factors applied to the image.

In the bottom:
UIImageOrientation
Specifies the possible orientations of an image.

typedef enum {
   UIImageOrientationUp,
   UIImageOrientationDown,   // 180 deg rotation
   UIImageOrientationLeft,   // 90 deg CCW
   UIImageOrientationRight,   // 90 deg CW
   UIImageOrientationUpMirrored,    // as above but image mirrored along
   // other axis. horizontal flip
   UIImageOrientationDownMirrored,  // horizontal flip
   UIImageOrientationLeftMirrored,  // vertical flip
   UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;

So    UIImageOrientationLeftMirrored,  UIImageOrientationRightMirrored.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
pgnatyukConnect With a Mentor Commented:
Here you will find another approach to rotate the image:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/1164-rotate-uiimage-help.html
0
 
beavoidAuthor Commented:
Thanks

This line got rotation stone cold.. on the ImageView, not the image.

rotation :

      imageView1.transform = CGAffineTransformMakeRotation(M_PI / 2.0);

enlarge:

        I couldn't find a transform single line solution like rotation for resizing.
        any suggestions?





0
 
pgnatyukCommented:
Read comment 33440659 again.
0
 
beavoidAuthor Commented:

If the implementation of a method is..

-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height {

What is its corresponding entry in the .h file?

and what would calling it look like?
0
 
pgnatyukCommented:
-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height;

UIImage* image = [self resizeImage: orignalImage width: 48 height: 92];
0
 
beavoidAuthor Commented:
I have your declaration for the method inside the {} of the interface  in  .h

and the error on the method implementation line is

"Expected specifier-qualifier-list before '-' token

My .h is attached

There is nothing before the  -


What could be missing?
//
//  TestViewController.h
//  Test
//
//  Created by Joann Crompton on 6/27/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface TestViewController : UIViewController {
	
	
	
	-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height;
	
	IBOutlet UILabel *label1;
	IBOutlet UILabel *label2;
	UIImageView * firstAnimation;
	UIImageView *imageView1, *ballImageView, *imageView2, *campFireView;
	
	CGRect myViewFrame;
	CGRect ballViewFrame;
	int XLocation;
	int fingerOffsetX;
	int fingerOffsetY;
	int YLocation;
	int starSizeX;
	int starSizeY;
	UIImage *myImage, *myImage1, *ballImage, *myImage2, *myImage3, *myImage4, *myImage5, *myImage6, *myImage7, *myImage8, *myImage9, *myImage10,*myImage11, *myImage12;
	NSTimer *mainTimer;
	int imgCenterX;
	int timer;
	int lastx;
	int testx, testy, ballx, bally,oldx,oldy;
	
	//frisbee* frisbees;
	
	int      animationImagesCount;
	UIImage* animationImages;
	int		 intAnimIndex;
	
	
	
	
	
}

@end

Open in new window

0
 
pgnatyukCommented:
It should be after } and before @end.
0
 
beavoidAuthor Commented:
So, all xcode class definitions have data members first in the {}
and  '-' method definitions before  @end
?
0
 
pgnatyukCommented:
yes. All instance variables are declared between {} in the interface section. All methods are after } and before @end. '-' means that this is an object method. '+' means that this is a class method (the static in C++).
0
 
beavoidAuthor Commented:
With a method indicator + or -

To clarify, do you mean.
static...  as in "exists/callable even if an object doesn't exist
?
0
 
pgnatyukCommented:
I'm not sure I can explain such fundamental things good enough for you.

When you create an object you use alloc, then init. The alloc method is with '+'. You call it for the class. This is the class method. (In C++, it's named as the static method.) You don't need to create an object of the class if you need to call such class method.

'-' is a usual way. When you have an object, you can call its methods. All of them (all public methods). The 'init' is an example of such method. In Objective-C there is a name for them - instance methods - if you have an instance of a class, you call these methods.

It is a very simple explanation. The real story is much longer.
0
 
beavoidAuthor Commented:

Do you think the rectangle proportions are expected to be the same? because arbitrary dimensions don't seem to be allowed ( no image gets loaded from the URL)

My..

id path1 = @"http://www.jamescomp.com/pics/runner/runningMan1pixenGIF.gif";
      NSURL *url1 = [NSURL URLWithString:path1];
      NSData *data1 = [NSData dataWithContentsOfURL:url1];
      myImage1 = [[UIImage alloc] initWithData:data1 cache:NO];
      

My call is:

      myImage1 = [self resizeImage: myImage1 width: 150 height: 80];


Is 150x80 a bad choice for dimensions?
0
 
pgnatyukCommented:
I think, for a beginning, it's better to see two images: myImage1 and myImage2.
If the current state works for you, leave it as is.

Dimensions is another story that I'm not ready to answer. If this resizeImage works fine, so everything is good. I already forget how the function is written.
0
 
beavoidAuthor Commented:
The rotation was solved with this line:

imageView1.transform = CGAffineTransformMakeRotation(M_PI / 2.0);

what would be the same kind of idea be for the size of a UIImage just loaded in?

Not necessarily changing the imageview, maybe the image itself.
For rotation, I changed the Imageview, for size, must I change the image?

How might
I double a UIimage's size?
The above resize code doesn't compile

Thanks All
0
 
pgnatyukConnect With a Mentor Commented:
I gave the link with example in the beginning:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/1164-rotate-uiimage-help.html

Take a look. There are few samples with this function.

I gave few ways to solve the question and asked on additional and new questions you asked. Now I'm leaving this thread. Sorry.

You are very welcome to ask new question.
0
 
beavoidAuthor Commented:
for enlargement, the solution is annoyingly simple.

or my viewframe, I simply entered size co-ords 200 x 150 in a new rectangle. It stretches the image to the new size.

      myViewFrame = CGRectMake(testx,testy,200,150);
0
 
pgnatyukCommented:
Yes. You knew about the view. You asked about the image here. I didn't know if there is a view somewhere. :(

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.