Hi,

I'm trying to add a feature to my application, where it collects all of the images related to an entity, and puts them into an image in a grid, so I'm planning on looping through the images, scaling them down then placing them onto a new(blank) image, changing the placement point each time.

I'm struggling with the whole image section, I think I can just use NSImage, but I think I need NSImageRep for some things, one of which being getting the original size to calulate the rescaled size. From what I can tell I can't just tell it to resize to 100 pixels high, I have to calculate what the width would be and set that at the same time (I know I've also got to bear in mind it's points not pixels).

Is there a good tutorial anywhere for this? It doesn't seem too complicated to me, if I can just get stated. So far I can't get the size from an NSImage, and I can't get it to set the NSImageRep. My images are stored as filepaths in the data, so the array I'll be looping though will contain strings for the filepath for each image.

Code I'm working with:
        - (IBAction)generateKitImages:(id)sender;
{
        NSObject *kit;
        kit = [[kits selectedObjects] objectAtIndex:0];
        
        NSString* fileName = [kit valueForKey:@"kitName"];
                                                                
        //create new image 300px square
         NSImage *image;
         NSSize size = NSMakeSize (300, 300);
         image = [[NSImage alloc] initWithSize:size];
        
        //select all images for kit
NSArray* kitImages = [kit valueForKeyPath:@"kitItems.kitItemProduct.productImage"];

        //set coordinates to x,y -> 0,100
        
        //for each image
        NSEnumerator *imageLoop = [kitImages objectEnumerator];
        NSString *imgPath;
        while ((imgPath = [imageLoop nextObject])) {
                NSImage *img = [[NSImage alloc]initWithContentsOfFile:imgPath];
                
                //resize to 100px high
                        //get original size
                        //calculate scale factor
                        //[img setScalesWhenResized: YES];
                        //[img setSize: NSMakeSize (100., 100.)];
                //get new coordinates
//if coordinates are too wide, start new row - if x>300, reset x to 0 and add 100 to y
                //apply image to view
                //get image width and add to coordinates
                //set new coordinates
        }
        //apply kit logo to view
        //apply kit date (text) to view
        //save files out
_______________________________________________

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

Reply via email to