initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:
INDEX>AppKit>NSBitmapImageRep> imageRepWithData
新しいアロケートされたNSBitmapImageRepオブジェクトを初期化します
- (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
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オブジェクトを初期化します。
引数
( unsigned char * _Nullable * )planes
planes: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>>
( NSInteger )width
width: Int
幅
( NSInteger )height
height: Int
高さ
( NSInteger )bps
bps: Int
サンプルのビット数
( NSInteger )spp
spp: Int
( BOOL )alpha
alpha: Bool
アルファを持つか
( BOOL )isPlanar
isPlanar: Bool
( NSString * )colorSpaceName
colorSpaceName: String,
カラースペース
( NSBitmapFormat )bitmapFormat
bitmapFormat: NSBitmapFormat,
ビットマップフォーマット
( NSInteger )rowBytes
rBytes: Int
1行のバイト数
( NSInteger )pixelBits
pBits: Int
ピクセルでのビット数
フレームワーク
ApplicationKit
クラス
NSBitmapImageRep
使用可能
10.4
参照
例文
//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