macOS/iOS API解説

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

目次

initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:

INDEX>AppKit>NSBitmapImageRep

指定した引数でビットマップ画像内容を初期化して返します

Objective-C

- (instancetype)initWithBitmapDataPlanes:(unsigned char * _Nullable *)planes
                              pixelsWide:(NSInteger)width
                              pixelsHigh:(NSInteger)height
                           bitsPerSample:(NSInteger)bps
                         samplesPerPixel:(NSInteger)spp
                                hasAlpha:(BOOL)alpha
                                isPlanar:(BOOL)isPlanar
                          colorSpaceName:(NSString *)colorSpaceName
                             bytesPerRow:(NSInteger)rowBytes
                            bitsPerPixel:(NSInteger)pixelBits

Swift

init?(bitmapDataPlanes planes: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>>,
            pixelsWide width: Int,
            pixelsHigh height: Int,
         bitsPerSample bps: Int,
       samplesPerPixel spp: Int,
              hasAlpha alpha: Bool,
              isPlanar isPlanar: Bool,
        colorSpaceName colorSpaceName: String,
           bytesPerRow rBytes: Int,
          bitsPerPixel pBits: Int)

解説

指定した引数でビットマップ画像内容を初期化して返します。

返り値

Objective-C

( instancetype )

Swift

ビットマップ画像

引数

Objective-C

( unsigned char * _Nullable * )planes

Swift

planes: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>>

Objective-C

( NSInteger )width

Swift

width: Int

Objective-C

( NSInteger )height

Swift

height: Int

高さ

Objective-C

( NSInteger )bps

Swift

bps: Int

解像度bit/pixel

Objective-C

( NSInteger )spp

Swift

spp: Int

サンプル/ピクセル

Objective-C

( BOOL )alpha

Swift

alpha: Bool

アルファチャンネルの有無YES/NO

Objective-C

( BOOL )isPlanar

Swift

isPlanar: Bool

プレーン配列か

Objective-C

( NSString * )colorSpaceName

Swift

colorSpaceName: String

カラースペース名

Objective-C

( NSInteger )rowBytes

Swift

rBytes: Int

一列のバイト数

Objective-C

( NSInteger )pixelBits

Swift

pBits: Int

ビット/ピクセル

フレームワーク

ApplicationKit

クラス

NSBitmapImageRep

使用可能

10.0

参照

例文

Objective-C

#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;
    //OpenPanelの結果のボタン番号
    int		  opRet;

        //OpenPanelでファイル選択   
    opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : imgTypes ];//選べるファイルタイプ

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

bmpRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **)&dat
                pixelsWide:640
                pixelsHigh:538
                bitsPerSample:8
                samplesPerPixel:3 
                hasAlpha:NO 
                isPlanar:NO
                colorSpaceName:NSDeviceRGBColorSpace 
                bytesPerRow:1920//pixelsWide*samplesPerPixel
                bitsPerPixel:24//bitsPerSample*samplesPerPixel
                ];  
                
    [img addRepresentation:bmpRep];
    [image setImage:img];
        NSLog([NSString stringWithFormat:@"bit / pixel:%d",[bmpRep bitsPerPixel]]);
    }
}

@end

Swift