Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách lấy độ sâu màu (color depth) và độ sâu pixel (pixel depth) màn hình trong JavaScript


Đối tượng window cung cấp nhiều phương thức lấy thông tin trình duyệt. Có screen.colorDepth và screen.pixelDepth để lấy độ sâu màu và độ sâu pixel màn hình. Thảo luận từng cái.

Độ sâu màu (Color depth)

screen.colorDepth trả về độ sâu màu: số bit dùng để hiển thị một màu. Máy tính hiện đại dùng 24-bit hoặc 32-bit cho độ phân giải màu.

Ví dụ

<html> <body> <p id="depth"></p> <script> document.getElementById("depth").innerHTML = "Screen color depth is " + screen.colorDepth; </script> </body> </html>

Kết quả

Screen color depth is 24


Độ sâu pixel (Pixel depth)

screen.pixelDepth trả về độ sâu pixel màn hình trình duyệt.

Ví dụ

<html> <body> <p id="depth"></p> <script> document.getElementById("depth").innerHTML = "Screen pixel depth is " + screen.pixelDepth; </script> </body> </html>

Kết quả

Screen pixel depth is 24