Just wanted to confirm that this is a repost of the previous thread? http://lists.apple.com/archives/cocoa-dev/2010/Oct/msg00117.html
--Kyle Sluder On Tue, Oct 5, 2010 at 2:07 AM, Amy Heavey <a...@willowtreecrafts.co.uk> wrote: > I've got two float values (x and y) that I'm using to change the coordinates > of a drawing action that is being looped through. I can add a value to x and > it draws the next image along, but I want to test the value of x and if it > is out of bounds I want to reset it to zero and increase y, so I get a grid > of images drawn. > > For some reason, even though I can do > x = x+128; > and it moves the image accross, x seems to be null so I can't test against > it, my if statement ' if (x > 300){' always fails. > > This must be something really simple I just can't see it this morning? I'd > appreciate any help. > > Many Thanks > > Amy > > Full code being used: > - (IBAction)generateKitImages:(id)sender; > { > NSObject *kit; > kit = [[kits selectedObjects] objectAtIndex:0]; > > NSString* fileName = [[kit valueForKey:@"kitName"] > stringByAppendingString:@".jpg"]; > NSString* kitimagePath = [[[[self applicationSupportFolder] > stringByAppendingPathComponent:@"images"] > stringByAppendingPathComponent:@"kit"] > stringByAppendingPathComponent:fileName]; > //NSLog(@"Kit Image Path: %@", kitimagePath); > //create new image 300px square > NSImage *targetImage; > NSSize targetSize = NSMakeSize (300, 300); > targetImage = [[NSImage alloc] initWithSize:targetSize]; > > > //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])) { > NSImage *img = [[NSImage > alloc]initWithContentsOfFile:imgPath]; > //NSLog(@"Image: %@",img); > //resize to 100px high > //get original size > //NSSize *origSize; > //origSize = [img size]; > //calculate scale factor > //[img setScalesWhenResized: YES]; > //[img setSize: NSMakeSize (100., 100.)]; > > //apply image to view > [targetImage lockFocus]; > [img drawInRect:NSMakeRect(x,y,100,100) > fromRect:NSMakeRect(x,y,100,100) > operation:NSCompositeCopy > fraction:1]; > > [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; > } > > } > //apply kit logo to view > //apply kit date (text) to view > //save files out > //create a NSBitmapImageRep > NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep > alloc]initWithData:[targetImage TIFFRepresentation]]; > //add the NSBitmapImage to the representation list of the target > [targetImage addRepresentation:bmpImageRep]; > > //get the data from the representation > NSData *data = [bmpImageRep representationUsingType: NSJPEGFileType > > properties: nil]; > > //write the data to a file > [data writeToFile: kitimagePath > atomically: NO]; > //link images to kit > [kit setValue:kitimagePath forKey:@"kitImage"]; > } > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/kyle.sluder%40gmail.com > > This email sent to kyle.slu...@gmail.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com