macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

representationOfImageRepsInArray:usingType:properties:

NSBitmapImageRepのバイナリ形式のデータを返します
+(NSData *)representationOfImageRepsInArray:(NSArray *)imageReps:
            usingType:(NSBitmapImageFileType)storageType:
            properties:(NSDictionary *)properties:

解説

NSBitmapImageRepのバイナリ形式のデータを返します。
【storageType】
● NSBMPFileType(10.0)
● NSGIFFileType(10.0)
● NSJPEGFileType(10.0)
● NSPNGFileType(10.0)
● NSTIFFFileType(10.0)
● NSJPEG2000FileType(10.4)
【properties】
画像タイプ特有の属性
NSString *NSImageCompressionMethod
NSString *NSImageCompressionFactor
NSString *NSImageDitherTransparency
NSString *NSImageRGBColorTable
NSString *NSImageInterlaced
NSString *NSImageColorSyncProfileData
NSString *NSImageFrameCount
NSString *NSImageCurrentFrame
NSString *NSImageCurrentFrameDuration
NSString *NSImageLoopCount
NSString *NSImageGamma
NSString *NSImageProgressive
NSString *NSImageEXIFData

返り値

( NSData * )

データ

引数

( NSArray * )imageReps

画像の内容

( NSBitmapImageFileType )storageType
( NSDictionary * )properties

プロパティ

フレームワーク

ApplicationKit

クラス

NSBitmapImageRep

Class Methods

使用可能

10.0

参照

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
    //開けるファイル拡張子の配列
    NSArray      *imgTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opImage       = [ NSOpenPanel openPanel ];
    //Imageを作る
    NSImage      *img = [[[NSImage alloc] initWithSize:NSMakeSize(100,100)] autorelease];
    NSBitmapImageRep *bmpRep;
    NSData *dat;
    NSData *dat2;
    //OpenPanelの結果のボタン番号
    int		  opRet;
    NSArray *currentReps;
    
        //OpenPanelでファイル選択   
    opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : imgTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        //NSDataを作ってファイルから読み込む
        dat = [NSData dataWithContentsOfFile: [ opImage filename ] ];
        bmpRep = [NSBitmapImageRep imageRepWithData:dat];
        [img addRepresentation:bmpRep];
        [image setImage:img];
     

        
        currentReps=[img representations]; 
        dat2 = [NSBitmapImageRep representationOfImageRepsInArray:currentReps
                                usingType:NSPNGFileType 
                                properties:nil];
                                
         NSLog([NSString stringWithFormat:@"data:%u",[dat2 length]]);                       
    }
}

@end