initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
指定した引数でビットマップ画像内容を初期化して返します
- (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
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)
解説
指定した引数でビットマップ画像内容を初期化して返します。
引数
( unsigned char * _Nullable * )planes
planes: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>>
( NSInteger )width
width: Int
幅
( NSInteger )height
height: Int
高さ
( NSInteger )bps
bps: Int
解像度bit/pixel
( NSInteger )spp
spp: Int
サンプル/ピクセル
( BOOL )alpha
alpha: Bool
アルファチャンネルの有無YES/NO
( BOOL )isPlanar
isPlanar: Bool
プレーン配列か
( NSString * )colorSpaceName
colorSpaceName: String
カラースペース名
( NSInteger )rowBytes
rBytes: Int
一列のバイト数
( NSInteger )pixelBits
pBits: Int
ビット/ピクセル
フレームワーク
ApplicationKit
クラス
NSBitmapImageRep
使用可能
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; //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