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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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-17-2009, 02:48 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 11
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
Old 03-17-2009, 12:06 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 11
Default

I've got this issue figured out:

I have created a temp UIImage in my addcircle method, which allows me to release the cgimage and return my formatted UImage.

I also created a new UIImage for this to be returned to in my refreshMap method.
puppet is offline   Reply With Quote
Old 03-24-2009, 12:38 PM   #3 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 1
Question

Quote:
Originally Posted by puppet View Post
I've got this issue figured out:

I have created a temp UIImage in my addcircle method, which allows me to release the cgimage and return my formatted UImage.

I also created a new UIImage for this to be returned to in my refreshMap method.
Hi,

I am having the exact same problem, I have a site map in the form of a PNG on which I want to draw a point when a certain action happens. I am having real trouble with even getting started. I was wondering if you could help me out a bit?

Thanks very much

Dave
hasitcometothis is offline   Reply With Quote
Old 03-25-2009, 09:40 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 11
Default

Quote:
Originally Posted by hasitcometothis View Post
Hi,

I am having the exact same problem, I have a site map in the form of a PNG on which I want to draw a point when a certain action happens. I am having real trouble with even getting started. I was wondering if you could help me out a bit?

Thanks very much

Dave
Well, I should warn you that I am a new an inexperienced developer, and my advice should be taken lightly.

The above example is not terrible. (please someone correct me if I'm wrong)

Where to start I suppose I would recommend the tutorials on this site, they really helped me understand handling touch events, and even in specific; touches in uiimageviews.
iphonedevcentral.org video tutorials

If you have any specific questions to ask (such as how to accomplish a specific task) I will try to answer them.
puppet is offline   Reply With Quote
Old 12-18-2009, 02:52 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: India
Posts: 2
Default drawing a line

Quote:
Originally Posted by puppet View Post
Well, I should warn you that I am a new an inexperienced developer, and my advice should be taken lightly.

The above example is not terrible. (please someone correct me if I'm wrong)

Where to start I suppose I would recommend the tutorials on this site, they really helped me understand handling touch events, and even in specific; touches in uiimageviews.
iphonedevcentral.org video tutorials

If you have any specific questions to ask (such as how to accomplish a specific task) I will try to answer them.


I want to ask you wheather how you can draw a line on a view. I'm currently developing a game, & need to draw a line creating d string of a bow. can u please help?
nehapundlik is offline   Reply With Quote
Reply

Bookmarks

Tags
memory, 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: 329
22 members and 307 guests
@sandris, ADY, BrianSlick, dacapo, Dani77, Dattee, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

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