如何使用 JavaScript 設定影像的亮度和對比度?
要設定亮度,請使用 brightness 屬性,而對於對比度,請使用 contrast 屬性。
示例
你可以嘗試執行下面的程式碼,使用 JavaScript 裡的影像濾鏡 −
<!DOCTYPE html>
<html>
<body>
<p>Click below to change the brightness and contrast of the image.</p>
<button onclick="display()">Edit Image</button><br><br>
<img id="myID" src="https://tutorialspoint.tw/videotutorials/images/tutorial_library_home.jpg"
alt="Tutorials Library" width="320" height="320">
<script>
function display() {
document.getElementById("myID").style.filter = "brightness(50%)";
document.getElementById("myID").style.filter = "contrast(50%)";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP