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

View Single Post
Old 03-17-2009, 01:48 AM   #1 (permalink)
puppet
Registered Member
 
Join Date: Jan 2009
Posts: 11
puppet is on a distinguished road
Default Drawing on UIIMage / Memory Issues

Greetings,

I'm trying to draw a circle on a map. all the separate pieces of this project work independently but when I put them all together it breaks.

I setup my UI in my viewDidLoad, retaining most of it.

I then use touch events to call a my refresh map method:
Code:
-(void)refreshMap{

	NSString *thePath = [NSString stringWithFormat:@"http://maps.google.com/staticmap?center=%f,%f&zoom=%i&size=640x640&maptype=hybrid",viewLatitude, viewLongitude, zoom];
	NSURL *url = [NSURL URLWithString:thePath];
	NSData *data = [NSData dataWithContentsOfURL:url];
	UIImage *mapImage = [[UIImage alloc] initWithData:data];

	mapImage = [self addCircle:(mapImage) influence:(70) latCon:(320) lonCon:(320)];
	NSLog(@"-- mapimageview retaincount %i",[mapImage retainCount]);	
	
	mapImageView.image = mapImage;
	[mapImage release];
	
}
Setup like this it will load the map with a circle once, but if the map is refreshed again it crashes.

If I comment out the mapImage release it works repeatedly but causes a memory leak.

The addCircle method I'm using:
Code:
-(UIImage *)addCircle:(UIImage *)img radius:(CGFloat)radius latCon:(CGFloat)lat lonCon:(CGFloat)lon{
    int w = img.size.width;
    int h = img.size.height; 
    lon = h - lon;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
	//draw the circle
	CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
	CGRect leftOval = {lat- radius/2, lon - radius/2, radius, radius};
	CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 0.3);
	CGContextAddEllipseInRect(context, leftOval);
	CGContextFillPath(context);
		
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
	
    return [UIImage imageWithCGImage:imageMasked];
}
Any insight/advise is greatly appreciated!
puppet is offline   Reply With Quote
 

» Advertisements
» Online Users: 453
17 members and 436 guests
apatsufas, baja_yu, buggen, ChrisYates, Feldspar, HowEver, ilmman, IphoneSdk, jNoxx, Kieren Harrold, mer10, Paul Slocum, rraagg, Rudy, taylor202, TheStalker, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,635
Threads: 94,096
Posts: 402,802
Top Poster: BrianSlick (7,990)
Welcome to our newest member, sadevb61
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.