Re: Confused about floats
Re: Confused about floats
- Subject: Re: Confused about floats
- From: Amy Heavey <email@hidden>
- Date: Tue, 5 Oct 2010 16:34:45 +0100
Thanks for all the help everyone, I'll take a look at it all, and
release where I need to!
Many Thanks
Amy
On 5 Oct 2010, at 4:17PM, Matt Neuburg wrote:
On Tue, 5 Oct 2010 10:17:31 +0100, Amy Heavey <email@hidden
>
said:
//select all images for kit
NSArray* kitImages = [kit
valueForKeyPath:@"kitItems.kitItemProduct.productImage"];
//set coordinates to x,y -> 0,0 to start
float x = 0;
float y = 0;
//for each image
NSEnumerator *imageLoop = [kitImages objectEnumerator];
NSString *imgPath;
while ((imgPath = [imageLoop nextObject])) {
The enumerator and the call to nextObject are now unnecessary; fast
enumeration has been invented. So unless you're running on an old
system
(of course, you might well be), you could say:
//for each image
for (NSString* imgPath in kitImages)
NSImage *img = [[NSImage alloc]initWithContentsOfFile:imgPath];
That's a memory leak. You are saying "alloc" without a balancing
"release".
//apply image to view
[targetImage lockFocus];
[img drawInRect:NSMakeRect(x,y,100,100)
fromRect:NSMakeRect(x,y,100,100)
operation:NSCompositeCopy
fraction:1];
Unlikely. As soon as you add 100 to x to and y, the fromRect value
will be
a rectangle outside the image. So it will probably be blank or black
or
something. You probably want the fromRect to be
NSMakeRect(0,0,100,100),
i.e. the whole of the image is to be used as the source (assuming
that the
image is 100 by 100).
[targetImage unlockFocus];
//set new coordinates
x = x+100;
//if coordinates are too wide, start new row - if x>300,
reset x
to
0 and add 100 to y
if(x > 300){
x = 0;
y = y+100;
}
}
NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep
alloc]initWithData:
[targetImage TIFFRepresentation]];
That's another memory leak.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden