2012-03-14 48 views
0

指定的目录路径使用此代码我试图调整所选择的图像,然后希望将其保存到特定的路径:调整图像大小,并把它保存在可可

-(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]; 

} 

我的问题是我不了解如何将其保存到thumbnailDirPath。

回答

-1

你应该将你的图像导出到文件中。 目前我只看到如何存储TIFF图像。

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

其中outputPathName是缩略图文件的文件名的路径。

0
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.8] forKey:NSImageCompressionFactor];  
NSData *tiffData = [img TIFFRepresentation]; 
NSData *JPEGData = [[NSBitmapImageRep imageRepWithData:tiffData] representationUsingType:NSJPEGFileType properties:options]; 
NSError *anError; 
if (![JPEGData outputPath options:0 error:&anError]) 
       MyLog(@"Error saving image: %@ to: %@", anError, outputPath); 

检查文档NSJPEGFileType,因为它会告诉你的储蓄的其他foramt选项,如PNG。

相关问题