2012-03-14 4 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画像を保存する方法しか見ていません。 outputPathNameがあなたのサムネイルファイルのファイル名とパスです

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

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); 

それはあなたに、このようなPNGとして、保存するための他のforamtのオプションが表示されますようNSJPEGFileTypeのマニュアルを確認してください。

関連する問題