如何使用 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.com/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