macOS/iOS API解説

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

目次

depth

INDEX>AppKit>NSScreen

スクリーンの色深度を返します

Swift

open var depth: NSWindow.Depth { get }

Objective-C

@property(readonly) NSWindowDepth depth

解説

スクリーンの色深度を返します。返される値は24ビットRGB,64ビットRGB,128ビットRGBのどれか。
  .twentyfourBitRGB  520
  .sixtyfourBitRGB   528
  .onehundredtwentyeightBitRGB  544

【Swift5.0】
何ビット表示かを知るためにはbitsPerPixelプロパティを使用します。

let depthbpp : Int = value.depth.bitsPerPixel

【Obj-C】
何ビット表示かを知るにはNSBitsPerPixelFromDepth()を使って変換します。
NSBitsPerPixelFromDepth([[NSScreen mainScreen] depth]);

返り値

NSWindow.Depth
( NSWindowDepth )

スクリーンの色深度

引数

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.0

参照

更新時のバージョン

OS X 10.14.5
Swift5.0

関連記事(外部サイト)

例文

Swift5.0

    //NSScreen depth
    @IBAction func function004(_ sender: Any) {
        let screenArray : [AnyObject] = NSScreen.screens
        for value in screenArray {
            let depth : Float = Float(value.depth)
            print("screen depth = \(depth)")
            
            let depthbpp : Int = value.depth.bitsPerPixel
            print("screen depth = \(depthbpp) bit")
            
            let depthE : NSWindow.Depth = value.depth
            switch depthE {
            case .twentyfourBitRGB:
                print("24 bit")
            case .sixtyfourBitRGB:
                print("64 bit")
            case .onehundredtwentyeightBitRGB:
                print("128 bit")
            default:
                print("default")
            }
        }
    }

Swift

    //NSWindow mainScreen()
    //NSWindow deepestScreen()
    //NSWindow screens()
    @IBAction func function001(sender: AnyObject) {
        let theScreen : NSScreen = NSScreen.mainScreen()!
        NSLog("main screen size=  (%.2f✕%.2f)",
                                    Float(theScreen.frame.size.width),
                                    Float(theScreen.frame.size.height) )
        //-> main screen size=  (1366.00✕768.00)
        
        let deepestScreen : NSScreen = NSScreen.deepestScreen()!
        NSLog("deepestScreen screen depth= %d", NSBitsPerPixelFromDepth(deepestScreen.depth) )
        //-> deepestScreen screen depth= 24
        
        let screenArray : [AnyObject] = NSScreen.screens()!
        for value in screenArray {
            NSLog("screen size=  (%.2f✕%.2f)",
                Float(value.frame.size.width),
                Float(value.frame.size.height) )
        }
        //-> screen size=  (1366.00✕768.00)
        //-> screen size=  (1920.00✕1080.00)

        
        var window : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: theScreen )
        windowArray.addObject(window) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        window.center()//ウインドウをスクリーンの中心に
        window.title = "ウインドウタイトル"//タイトル設定
        window.orderFront(self)//前面に
        window.makeKeyAndOrderFront(self)//表示
    }

Obj-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
int windowDep;
windowDep = NSBitsPerPixelFromDepth([[NSScreen mainScreen] depth]);


NSLog([NSString stringWithFormat:@"%d",windowDep]);

}

@end