Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีดึง Pixel Depth ของหน้าจอใน JavaScript

ใช้ Property screen.pixelDepth เพื่อดึงความลึกของสี (Bits per Pixel) ของหน้าจอผู้ใช้

ตัวอย่างโค้ด

<!DOCTYPE html>
<html>
  <body>
    <script>
      document.write("Screen width: " + screen.width);
      document.write("<br>Screen height: " + screen.height);
      document.write("<br>Pixel Depth: " + screen.pixelDepth);
    </script>
  </body>
</html>

คำอธิบาย Properties

Propertyความหมายค่าตัวอย่าง
screen.widthความกว้างหน้าจอ (px)1920
screen.heightความสูงหน้าจอ (px)1080
screen.pixelDepthBit ต่อ Pixel (Color Depth)24, 30, 32
screen.colorDepthBit ต่อสี (มักเท่ากัน)24

ค่าที่พบบ่อย

  • 24-bit: True Color (16.7M สี) — มาตรฐานปัจจุบัน
  • 30-bit: Deep Color (1.07B สี) — หน้าจอ High-end
  • 32-bit: 24-bit Color + 8-bit Alpha Channel
  • 16-bit: High Color (65K สี) — เก่า/Embedded

ความแตกต่าง pixelDepth vs colorDepth

  • pixelDepth — Bit ทั้งหมดต่อ Pixel (รวม Alpha/Padding)
  • colorDepth — Bit ใช้แสดงสีจริง (มักเท่ากันใน Browser สมัยใหม่)

หมายเหตุ: ค่าเหล่านี้อ่านจาก Hardware/OS ไม่ใช่ Browser Zoom Level