[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I rotate, enlarge UIIMAGES in code?

Posted on 2010-08-14
20
Medium Priority
?
2,365 Views
Last Modified: 2012-05-10
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?

0
Comment
Question by:beavoid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
20 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 2000 total points
ID: 33440659
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
 

Author Comment

by:beavoid
ID: 33449672
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33449738
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 2000 total points
ID: 33449771
Here you will find another approach to rotate the image:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/1164-rotate-uiimage-help.html
0
 

Author Comment

by:beavoid
ID: 33451314
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33451709
Read comment 33440659 again.
0
 

Author Comment

by:beavoid
ID: 33458347

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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33458391
-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height;

UIImage* image = [self resizeImage: orignalImage width: 48 height: 92];
0
 

Author Comment

by:beavoid
ID: 33459301
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33459311
It should be after } and before @end.
0
 

Author Comment

by:beavoid
ID: 33460848
So, all xcode class definitions have data members first in the {}
and  '-' method definitions before  @end
?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33461219
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
 

Author Comment

by:beavoid
ID: 33465388
With a method indicator + or -

To clarify, do you mean.
static...  as in "exists/callable even if an object doesn't exist
?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33467563
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
 

Author Comment

by:beavoid
ID: 33490037

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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33490562
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
 

Author Comment

by:beavoid
ID: 33507314
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
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 2000 total points
ID: 33507971
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
 

Author Comment

by:beavoid
ID: 33620251
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33621136
Yes. You knew about the view. You asked about the image here. I didn't know if there is a view somewhere. :(

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
Learn new improvements released by Google for Google Calendar. Noted in this article are simple tips and tricks that can make your everyday use of Google Calendar better.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question