Search code examples
objective-cxcodecocoansimage

Resizing image and saving it to the specified directory path in Cocoa


Using this code I am trying to resize the selected image and then want to save it to a specific path:

-(void)processImage:(NSString*)inputPath:(int)imageWidth:(int)imageHeight:(NSString*)outputPath {

    NSImage * img = [NSImage imageNamed:inputPath];
    [img setSize: NSMakeSize(imageWidth,imageHeight)];

}

-(void)startProcessingImages {

    int i; // Loop counter.

    // Loop through all the files and process them.
    for( i = 0; i < [files count]; i++ )
    {
        inputFilePath = [[files objectAtIndex:i] retain];
        NSLog(@"filename::: %@", inputFilePath);

        // Do something with the filename.

        [selectedFile setStringValue:inputFilePath];

        NSLog(@"selectedFile:::: %@", selectedFile);
    }

    NSLog(@"curdir:::::%@", inputFilePath);

    NSString *aString = [[NSString stringWithFormat:@"%@%@%@", thumbnailDirPath , @"/" , fileNameNumber] retain];

    fileNameJPG = [[aString stringByAppendingString:@".jpg"] retain];

    [self processImage:inputFilePath: 66  :55  :thumbnailDirPath];
    [self processImage:inputFilePath: 800 :600 :thumbnailDirPath];
    [self processImage:inputFilePath: 320 :240 :thumbnailDirPath];

}

My issue is I am not getting that how to save it to thumbnailDirPath.


Solution

  • you should do export your image into file. currently I only see how to store the TIFF image.

    [[img TIFFRepresentation] writeToFile:outputPathName atomacally:NO];
    

    Where outputPathName is the path with file name for your thumbnail file.