• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Confused about floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confused about floats


  • Subject: Re: Confused about floats
  • From: Matt Neuburg <email@hidden>
  • Date: Tue, 05 Oct 2010 08:17:30 -0700
  • Thread-topic: Confused about floats

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

  • Follow-Ups:
    • Re: Confused about floats
      • From: Amy Heavey <email@hidden>
    • Re: Confused about floats
      • From: Amy Heavey <email@hidden>
  • Prev by Date: RE: Confused about floats
  • Next by Date: Re: Confused about floats
  • Previous by thread: Re: Confused about floats
  • Next by thread: Re: Confused about floats
  • Index(es):
    • Date
    • Thread