2

私はこのコードを持っています:

NSImage * strImage = [[NSImage alloc]initWithContentsOfFile:ImageFilePath] ;
NSData *imageData = [strImage TIFFRepresentation];

私が必要とするのは、imageData を JPEG 形式に変換することです。これが同じように機能することを望みQImage save()ます。

どのようsave()に機能するかを確認できるように、リンクを提供します: http://doc.qt.nokia.com/4.6/qimage.html#save

私を助けてください。

4

1 に答える 1

14

CocoaDev から...作成後に何かを行う場合NSImage:

NSData *imageData = [image TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSNumber *compressionFactor = [NSNumber numberWithFloat:0.9];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:compressionFactor
                                         forKey:NSImageCompressionFactor];
imageData = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
[imageData writeToFile:filename atomically:YES];

前に他に何もしない場合NSImage

NSArray *representations = [myImage representations];
NSNumber *compressionFactor = [NSNumber numberWithFloat:0.9];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:compressionFactor
                                         forKey:NSImageCompressionFactor];
NSData *bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:representations 
                                       usingType:NSJPEGFileType 
                                       properties:imageProps];    
[bitmapData writeToFile:filename atomically:YES];
于 2010-09-13T08:11:30.450 に答える