当前位置:网站首页>Canvas draw picture
Canvas draw picture
2022-06-24 09:51:00 【Time202051】
First getImageData Get all pixel data of the picture ( Array )
putImageData This is where the acquired data is plotted
Be careful : Ordinary canvas Elements can be drawn directly like this , However, if it is an imported image, it must pass createImageData Create a transparent area , Then assign the obtained picture pixel data to createImageData Every pixel of
// var canvas = document.getElementById('canvas');
// var ctx = canvas.getContext('2d');
var canvasa = document.getElementById('canvasa');
var ctxa = canvasa.getContext('2d');
var canvasb = document.getElementById('canvasb');
var ctxb = canvasb.getContext('2d');
// ctx.fillStyle = "green"
// ctx.fillRect(0, 0, 50, 50)
var imageData;
var image = new Image()
image.src = './image.jfif'
image.onload = function () {
ctxb.drawImage(this, 0, 0, this.width, this.height)
imageData = ctxb.getImageData(0, 0, canvasb.width, canvasb.height)
console.log(imageData);
var cImage = ctxa.createImageData(canvasa.width, canvasa.height)
for (var i = 0; i < imageData.data.length; i += 4) {
//rbg And transparency +4
cImage.data[i + 0] = imageData.data[i + 0]
cImage.data[i + 1] = imageData.data[i + 1]+ 16
cImage.data[i + 2] = imageData.data[i + 2]
cImage.data[i + 3] = imageData.data[i + 3]
}
console.log(cImage);
ctxa.putImageData(cImage, 0, 0, 0, 0, canvasa.width, canvasa.height)
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas id="canvasa" width="500" height="300" style=" border: 1px solid #c03;"></canvas>
<canvas id="canvasb" width="500" height="300" style=" border: 1px solid #06C1AE;"></canvas>
<!-- <canvas id="canvas" width="500" height="300" style=" border: 1px solid #1122c0;"></canvas> -->
<!-- <script src="./image.js"> -->
<!-- </script> -->
<script src="./image1.js"></script>
</body>
</html>
This is getImageData Obtained pixel data . Every time 4 One for a group , by rgb And transparency 
On the left canvas Draw the , Original picture on the right
For each rgb Of g Added a few pixels , therefore canvas Drawn green . Guess filter may be to modify each pixel value through some algorithm 
Pay attention to the service , Right click Open with Live Server start-up 

边栏推荐
- 如何管理海量的网络基础设施?
- Algorithm - the K row with the weakest combat power in the matrix (kotlin)
- 使用Live Chat促進業務銷售的驚人技巧
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
- el-table表格的拖拽 sortablejs
- 如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!
- Implementation of simple floating frame in WindowManager
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- Operator details
- 带文字的seekbar : 自定义progressDrawable/thumb :解决显示不全
猜你喜欢

记录一下MySql update会锁定哪些范围的数据

R 椭圆随机点产生并画图

About thinkphp5, use the model save() to update the data prompt method not exist:think\db\query- & gt; Error reporting solution

使用Live Chat促進業務銷售的驚人技巧

Indexeddb local storage, homepage optimization

June 13-19, 2022 AI industry weekly (issue 102): career development

深度学习论文阅读目标检测篇(七)中英对照版:YOLOv4《Optimal Speed and Accuracy of Object Detection》

canvas 绘制图片

impdp导schema报ORA-31625异常处理

Idea cannot save settings source root d:xxxx is duplicated in module XXX
随机推荐
Nlp-d59-nlp game D28 - I think it's OK - stage summary - mentality adjustment
How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
Learn Tai Chi Maker - esp8226 (12) esp8266 multitasking
ThinkPHP5多语言切换项目实战
Algorithm -- find and maximum length k subsequence (kotlin)
带文字的seekbar : 自定义progressDrawable/thumb :解决显示不全
R ellipse random point generation and drawing
转:三星电子CEO:一切决策都要从认清自己开始
Reasons for the failure of digital transformation and the way to success
WindowManager 简单悬浮框的实现
el-table点击添加行样式
2021-08-17
Symbol. Iterator iterator
5 minutes, excellent customer service chat handling skills
100 GIS practical application cases (XIV) -arcgis attribute connection and using Excel
ggplot2颜色设置总结
In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection
五心红娘
Honeypot 2 hfish, ehoney
threejs的 mmd模型加载+轮廓加载+动画加载+音频加载+相机动画加载+ammojs加载 gltf模型的加载 +gltf的反射调整