11-14-2011, 04:41 PM
#1 (permalink )
Registered Member
Join Date: Oct 2010
Posts: 1,210
Call method from these classes?
Hey,
I am looking at this tutorial:
Resize a UIImage the right way — Trevor’s Bike Shed
The thing is, if I download the files, it comes up with 6 files. These files are 'add-ons' to UIImage.
But does anyone know how I can actually call one of these methods from my UIViewController?
I really need help with this!
Thanks!
11-14-2011, 06:18 PM
#2 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
It looks like they are categories. Categories allow you to extend the functionality of a class by adding methods. So you'd call the methods outlined in the header files as if they were native UIImage methods.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.
New app - See screenshots and details at
www.globaclock.com .
If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
11-20-2011, 02:16 AM
#3 (permalink )
Registered Member
Join Date: Oct 2010
Posts: 1,210
This isn't from the link you showed me but this code does what this thread related to, I get a leak in this line:
Code:
newImage = [[UIImage imageWithCGImage:imageMasked] retain];
Although in the following line they do:
Code:
CGImageRelease(imageMasked);
Any idea how to fix this leak?
11-20-2011, 02:23 AM
#4 (permalink )
Registered Member
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
Quote:
Originally Posted by
Objective Zero
This isn't from the link you showed me but this code does what this thread related to, I get a leak in this line:
Code:
newImage = [[UIImage imageWithCGImage:imageMasked] retain];
Although in the following line they do:
Code:
CGImageRelease(imageMasked);
Any idea how to fix this leak?
I'm guessing newImage is leaking rather than imageMasked. You are retaining newImage are you releasing it?
__________________
SQLed - Your Database Manager on the go
iAZConverter - Converts everything from A to Z
11-20-2011, 01:16 PM
#5 (permalink )
Registered Member
Join Date: Oct 2010
Posts: 1,210
This is the whole method:
Code:
-(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight
{
UIImage * newImage = nil;
if( nil != img)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextBeginPath(context);
CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
[img release];
newImage = [[UIImage imageWithCGImage:imageMasked] retain];
CGImageRelease(imageMasked);
[pool release];
}
return newImage;
}
I am just not sure how to properly release it. Do I autorelease it or do I release it before I do pool release?
11-20-2011, 04:50 PM
#6 (permalink )
Registered Member
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
You don't need to retain it. imageWithCGImage: returns an autorelease object so there is no need to retain it. As soon as the autorelease pool is drained it will be released.
__________________
SQLed - Your Database Manager on the go
iAZConverter - Converts everything from A to Z
11-20-2011, 05:36 PM
#7 (permalink )
Registered Member
Join Date: Oct 2010
Posts: 1,210
I actually changed the whole method I used to this (it achieves the same thing):
Code:
- (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r {
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
[[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
cornerRadius:r] addClip];
[orig drawInRect:(CGRect){CGPointZero, orig.size}];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
And this one has no leaks or warnings!
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 393
17 members and 376 guests
7twenty7 , Alex-alex , Apptronics RBC , baja_yu , chiataytuday , dre , gwelmarten , ipodphone , jeroenkeij , jleannex55 , matador1978 , mbadegree , n00b , pbart , QuantumDoja , Retouchable , usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55