macOS/iOS API解説

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

目次

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

INDEX>AppKit>NSBitmapImageRep> imageRepWithData

新しいアロケートされた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
                            bitmapFormat:(NSBitmapFormat)bitmapFormat
                             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,
          bitmapFormat bitmapFormat: NSBitmapFormat,
           bytesPerRow rBytes: Int,
          bitsPerPixel pBits: Int)

解説

新しいアロケートされたNSBitmapImageRepオブジェクトを初期化します。

返り値

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

サンプルのビット数

Objective-C

( NSInteger )spp

Swift

spp: Int

Objective-C

( BOOL )alpha

Swift

alpha: Bool

アルファを持つか

Objective-C

( BOOL )isPlanar

Swift

isPlanar: Bool

Objective-C

( NSString * )colorSpaceName

Swift

colorSpaceName: String,

カラースペース

Objective-C

( NSBitmapFormat )bitmapFormat

Swift

bitmapFormat: NSBitmapFormat,

ビットマップフォーマット

Objective-C

( NSInteger )rowBytes

Swift

 rBytes: Int

1行のバイト数

Objective-C

( NSInteger )pixelBits

Swift

pBits: Int

ピクセルでのビット数

フレームワーク

ApplicationKit

クラス

NSBitmapImageRep

使用可能

10.4

参照

例文

Objective-C

Swift

    //NSBitmapImageRep
    //init(bitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:)
    //RGBRGBRGBのデータ
    //Swift2.0
    @IBAction func function004(sender: AnyObject) {
        
        let bitmapWidth : Int = 640
        let bitmapHeight : Int = 480
        let bitmapSample : Int = 3  //アルファがあるときは1つ増える
        let bufferSize  = ( bitmapWidth*bitmapHeight*bitmapSample)//幅*高さ*ピクセルあたりのサンプル数
        var buffer = UnsafeMutablePointer<UInt8>.alloc(bufferSize)//8
        //オフスクリーンを作成
        let theBitmap = NSBitmapImageRep(
                bitmapDataPlanes: &buffer,  //バッファ
                pixelsWide: bitmapWidth,    //幅
                pixelsHigh: bitmapHeight,            //高さ
                bitsPerSample: 8,           //サンプルあたりのビット(色)
                samplesPerPixel: bitmapSample,//ピクセル当たりのサンプル数(RGBなら3,RGBAなら4)
                hasAlpha: false,            //アルファ(不透明度)があるときはtrue
                isPlanar: false,            //プレーン化されるかfalseだとRGBRGBRGBRGBとなる
                colorSpaceName: NSDeviceRGBColorSpace,//カラースペース
                bytesPerRow: 0,
                bitsPerPixel: 0
        )
        //ビットマップの操作、ここではバッファのメモリを書き換える
        //バッファをクリア
        for index in 0..<bufferSize
        {
            buffer[index] = 0
        }
        //上から半分赤で埋め尽くす
        for index in 0..<(bufferSize/3)/2
        {
            buffer[index*3] = 255
        }
        //メモリ書き換え終了
        
        
        //ビットマップの加工、ここではブルーに塗りつぶす
        //setColorで塗る
        for y in 20...460 {
            for x in 20...620 {
                theBitmap!.setColor(NSColor.blueColor(), atX: x, y: y)
            }
        }
        //setColor終了
        
        //ビットマップフォーマット
        switch (theBitmap!.bitmapFormat){
        case NSBitmapFormat.NSAlphaFirstBitmapFormat :
            NSLog("NSAlphaFirstBitmapFormat ")
        case NSBitmapFormat.NSAlphaNonpremultipliedBitmapFormat :
            NSLog("NSAlphaNonpremultipliedBitmapFormat ")
        case NSBitmapFormat.NSFloatingPointSamplesBitmapFormat :
            NSLog("NSFloatingPointSamplesBitmapFormat ")
        case NSBitmapFormat.NS16BitLittleEndianBitmapFormat :
            NSLog("NS16BitLittleEndianBitmapFormat ")
        case NSBitmapFormat.NS32BitLittleEndianBitmapFormat :
            NSLog("NS32BitLittleEndianBitmapFormat ")
        case NSBitmapFormat.NS16BitBigEndianBitmapFormat :
            NSLog("NS16BitBigEndianBitmapFormat ")
        case NSBitmapFormat.NS32BitBigEndianBitmapFormat :
            NSLog("NS32BitBigEndianBitmapFormat ")
        default:
            NSLog("default")
        }
        
        //ピクセルあたりのビット数
        NSLog("bitsPerPixel = %d",theBitmap!.bitsPerPixel)
        
        //Planeごとのバイト数
        NSLog("bytesPerPlane = %d",theBitmap!.bytesPerPlane)
        
        //画像の1ラインのバイト数
        NSLog("bytesPerRow = %d",theBitmap!.bytesPerRow)
        
        //プレーンの数
        NSLog("numberOfPlanes = %d",theBitmap!.numberOfPlanes)
        
        //サンプル数
        NSLog("samplesPerPixel = %d",theBitmap!.samplesPerPixel)
        
        //チャンネルあたりのバイト数
        NSLog("byte per pixel = %d",(theBitmap!.bytesPerRow/theBitmap!.samplesPerPixel) )
        
        
        
        
        
//        for index in 0..<bufferSize
//        {
//            NSLog("%d",buffer[index])
//        }
        
        //ファイル書き出し
        let destiPath : NSString = ("~/Desktop/test004.png" as NSString).stringByExpandingTildeInPath
        
        theBitmap!.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:])?.writeToFile(destiPath as String, atomically: true)
        
    }
|

編集時のバージョン

10.11