javascript - 如何在 Mac 桌面上成功显示使用 HTML5 画布绘制的图像的对比度差异?
问题描述
我想在我的屏幕上为我的实验显示两个 Gabor 补丁。我正在使用 HTML5 画布绘制 Gabor 补丁。我希望两个补丁具有不同的对比度。当我使用 chrome 和 firefox 在 Windows PC 和笔记本电脑上运行代码时,补丁成功地呈现出所需的对比度差异。但是,当我使用 Firefox 和 Chrome 在 Mac 桌面上运行它时,gabor 补丁以绝对对比度显示。gabor 补丁的对比度级别不会改变。也就是说,补丁最终具有相同的对比度级别,即 1。1 是最亮的对比度。这是我的代码:
var c = document.getElementById("myCanvas");
var context = c.getContext("2d");
const my_gradient = context.createLinearGradient(0, 0, 200, 0);
const bands = 10;
const colors = ["#000", "#FFF"];
const stops = bands * colors.length;
var pos = 0;
while (pos <= stops) {
my_gradient.addColorStop(pos / stops, colors[pos % colors.length]);
pos++;
}
context.fillStyle = my_gradient;
context.filter = "contrast(0.2)"
context.fillRect(100, 200, 100, 100)
context.stroke()
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #D3D3D3;">
Your browser does not support the HTML canvas tag.</canvas>
解决方案
推荐阅读
- java - Java - 基于文件扩展名获取图标
- perl - 使用 Perl 或 Powershell,如何比较 2 个 CSV 文件并仅获取新行?
- c# - 将 SQL 查询结果格式化为电子邮件正文 (SMTP) C# 控制台应用程序
- azure - Azure AD B2C 页面 UI 自定义不支持 Bootstrap 吗?
- c++ - 范围内的结构与函数定义
- python - 具有用户特定计数器的不和谐机器人
- javascript - 在验证中排除字符串列表 - 正则表达式
- python - 字典理解与常规字典创建的语义差异:为什么
. 行为不同于 ? - python - Windows 的 Python 服务有几个问题
- gnuplot - 如何在gnuplot中找到想法位置的坐标