Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-03-2011, 05:03 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Question Passing UIImage through 3 classes

Hi all,
I have a UIImage. This UIImage has to start from a UIView, and pass through a MainViewController to the FlipsideViewController. The UIImage is created with UIGraphicsGetImageFromCurrentImageContext(), which as far as I know can only be called from drawRect. Now the NSLog shows that the image has been generated from the UIView, but it appears after the other log statements in the other classes. Obviously drawRect is taking its own sweet time, and the compiler is moving on. Here's the relevant code.

UIView.m:
Code:
(void) drawRect:(CGRect)rect
{
	UIGraphicsBeginImageContext(self.bounds.size);
        //drawing stuff	
	if (gettingImage == YES) 
	{
		shapeImage = UIGraphicsGetImageFromCurrentImageContext();
		gettingImage = NO;
	}
	
	UIGraphicsEndImageContext();

}

- (UIImage *) getUIImage
{
	gettingImage = YES;
	[self setNeedsDisplay];
	return shapeImage;
}
MainViewController.m:
Code:
- (IBAction)showInfo:(id)sender {    
	
	FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
	controller.delegate = self;
	
	UIImage *shape = [viewer getUIImage];  //Viewer is an object of UIView
	[controller getImageForFlipside:shape];
	controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:controller animated:YES];
	
	[controller release];
}
FlipsideViewController.m:
Code:
- (void)viewDidLoad 
{
    [super viewDidLoad];
	UIImageView *shapeImage = [[UIImageView alloc] initWithImage:shape]; //Shape is an instance variable UIImage
	shapeImage.frame = CGRectMake(100.0, 126.0, shape.size.width, shape.size.height);
	[self.view addSubview:shapeImage];
}

- (void) getImageForFlipside:(UIImage *)image
{
	shape = image;
}
So everything compiles okay, but checking all the steps along the way gives me this:
Code:
2011-03-03 16:50:43.093 The Escherizer[95694:207] <UIImageView: 0x4b2af80; frame = (100 126; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x4b2b550>>
2011-03-03 16:50:43.095 The Escherizer[95694:207] shapeImage.image: (null) //This and above from FlipsideViewController
2011-03-03 16:50:43.100 The Escherizer[95694:207] shapeImage = <UIImage: 0x4b2c4d0> //from drawRect in UIView
architectpianist is offline   Reply With Quote
Reply

Bookmarks

Tags
class, drawrect, flipsideviewcontroller, setneedsdisplay, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 369
16 members and 353 guests
Absentia, akphyo, apatsufas, BinHex, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0