- 浏览: 2579146 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
HTML5(三)color pixel and picture
1.color
every pixel (picture element) are consist of 4 bytes.
first byte decide the red value
second byte decide the green value
third byte decide the blue value
fourth byte decide the transparency value
the value range is 0~255
(255,0,0,255) stand for pure red, in memory it is 11111111 00000000 000000000 11111111
2. manage pixel
Object ImageData stores the pixel value, it contains width,height and data properties. data property is a array.
imageData.data[index*4 + 0]
imageData.data[index*4 + 1]
imageData.data[index*4 + 2]
imageData.data[index*4 + 3]
They stands for the index+1 pixel red value, green value and blue value and transparency value.
The picture is width * height pixels. So we have width * height * 4 values in data array.
There are 3 method in context:
createImageData(width,height) all the pixels are rgba(0,0,0,0)
getImageData(x,y,width,height)
putImageData(data,x,y)
3. simple sample
my file is test3.html, we must put in under apache and test it.
<canvas id="test1" width="280" height="200" style="background-image:url(banner1.gif)">
you are out!
</canvas>
<br />
red value:<input type="range" min="1" max="100" onchange="colorChange(event,0)"/>
<br />
green value:<input type="range" min="1" max="100" onchange="colorChange(event,1)"/>
<br />
blue value:<input type="range" min="1" max="100" onchange="colorChange(event,2)"/>
<br />
transparency:<input type="range" min="1" max="100" onchange="colorChange(event,3)"/>
<script type="text/javascript">
//get the context
var canvas = document.getElementById("test1");
var ctx = canvas.getContext("2d");
//get width and height of canvas
var width = parseInt(canvas.getAttribute("width"));
var height = parseInt(canvas.getAttribute("height"));
//load the image
var image = new Image();
image.onload =imageLoaded;
image.src = "banner2.gif";
//save the array of image data
var imageData=null;
function imageLoaded() {
// draw the image on canvas
ctx.drawImage(image, 0, 0);
imageData = ctx.getImageData(0, 0, width, height);
}
function colorChange(event,offset){
imageLoaded();
for (var y = 0; y < imageData.height; y++) {
for (x = 0;x < imageData.width; x++) {
//index = pixel number
var index = y * imageData.width + x;
var p = index * 4;
var color = imageData.data[p + offset] * event.target.value / 50;
// color value range is [0..255]
color = Math.min(255, color);
//update the value in array
imageData.data[p + offset]=color
}
}
ctx.putImageData(imageData, 0, 0);
}
</script>
4. draw the random color point on canvas
my test file is test3-1.html:
<canvas id="test2" width="300" height="300" style=" background-color: black">
you are out.
</canvas>
<input type="button" value="draw point" onclick="interval=setInterval(randomPixel,1);" />
<input type="button" value="stop" onclick="clearInterval(interval);"/>
<input type="button" value="clear" onclick="clearCanvas();"/>
<script type="text/javascript">
//get the context
var canvas = document.getElementById("test2");
var ctx = canvas.getContext("2d");
//get width and height
var width = parseInt(canvas.getAttribute("width"));
var height = parseInt(canvas.getAttribute("height"));
var imageData = ctx.createImageData(width, height);
function randomPixel(){
var x= parseInt(Math.random()*width);
var y= parseInt(Math.random()*height);
var index = y * width + x;
var p = index * 4;
imageData.data[p + 0] = parseInt(Math.random() * 256);
imageData.data[p + 1] = parseInt(Math.random() * 256);
imageData.data[p + 2] = parseInt(Math.random() * 256);
imageData.data[p + 3] =parseInt(Math.random() * 256);
ctx.putImageData(imageData,0,0);
}
function clearCanvas(){
ctx.clearRect(0,0,width,height);
imageData = ctx.createImageData(width, height);
}
</script>
references:
http://www.blogjava.net/myqiao/category/46360.html
1.color
every pixel (picture element) are consist of 4 bytes.
first byte decide the red value
second byte decide the green value
third byte decide the blue value
fourth byte decide the transparency value
the value range is 0~255
(255,0,0,255) stand for pure red, in memory it is 11111111 00000000 000000000 11111111
2. manage pixel
Object ImageData stores the pixel value, it contains width,height and data properties. data property is a array.
imageData.data[index*4 + 0]
imageData.data[index*4 + 1]
imageData.data[index*4 + 2]
imageData.data[index*4 + 3]
They stands for the index+1 pixel red value, green value and blue value and transparency value.
The picture is width * height pixels. So we have width * height * 4 values in data array.
There are 3 method in context:
createImageData(width,height) all the pixels are rgba(0,0,0,0)
getImageData(x,y,width,height)
putImageData(data,x,y)
3. simple sample
my file is test3.html, we must put in under apache and test it.
<canvas id="test1" width="280" height="200" style="background-image:url(banner1.gif)">
you are out!
</canvas>
<br />
red value:<input type="range" min="1" max="100" onchange="colorChange(event,0)"/>
<br />
green value:<input type="range" min="1" max="100" onchange="colorChange(event,1)"/>
<br />
blue value:<input type="range" min="1" max="100" onchange="colorChange(event,2)"/>
<br />
transparency:<input type="range" min="1" max="100" onchange="colorChange(event,3)"/>
<script type="text/javascript">
//get the context
var canvas = document.getElementById("test1");
var ctx = canvas.getContext("2d");
//get width and height of canvas
var width = parseInt(canvas.getAttribute("width"));
var height = parseInt(canvas.getAttribute("height"));
//load the image
var image = new Image();
image.onload =imageLoaded;
image.src = "banner2.gif";
//save the array of image data
var imageData=null;
function imageLoaded() {
// draw the image on canvas
ctx.drawImage(image, 0, 0);
imageData = ctx.getImageData(0, 0, width, height);
}
function colorChange(event,offset){
imageLoaded();
for (var y = 0; y < imageData.height; y++) {
for (x = 0;x < imageData.width; x++) {
//index = pixel number
var index = y * imageData.width + x;
var p = index * 4;
var color = imageData.data[p + offset] * event.target.value / 50;
// color value range is [0..255]
color = Math.min(255, color);
//update the value in array
imageData.data[p + offset]=color
}
}
ctx.putImageData(imageData, 0, 0);
}
</script>
4. draw the random color point on canvas
my test file is test3-1.html:
<canvas id="test2" width="300" height="300" style=" background-color: black">
you are out.
</canvas>
<input type="button" value="draw point" onclick="interval=setInterval(randomPixel,1);" />
<input type="button" value="stop" onclick="clearInterval(interval);"/>
<input type="button" value="clear" onclick="clearCanvas();"/>
<script type="text/javascript">
//get the context
var canvas = document.getElementById("test2");
var ctx = canvas.getContext("2d");
//get width and height
var width = parseInt(canvas.getAttribute("width"));
var height = parseInt(canvas.getAttribute("height"));
var imageData = ctx.createImageData(width, height);
function randomPixel(){
var x= parseInt(Math.random()*width);
var y= parseInt(Math.random()*height);
var index = y * width + x;
var p = index * 4;
imageData.data[p + 0] = parseInt(Math.random() * 256);
imageData.data[p + 1] = parseInt(Math.random() * 256);
imageData.data[p + 2] = parseInt(Math.random() * 256);
imageData.data[p + 3] =parseInt(Math.random() * 256);
ctx.putImageData(imageData,0,0);
}
function clearCanvas(){
ctx.clearRect(0,0,width,height);
imageData = ctx.createImageData(width, height);
}
</script>
references:
http://www.blogjava.net/myqiao/category/46360.html
发表评论
-
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 263MongoDB 2019(3)Security and Aut ... -
Memory Leak in NodeJS
2018-12-20 06:26 762Memory Leak in NodeJS I have d ... -
Remote Desktop Client
2018-12-07 13:19 1223Remote Desktop Client There is ... -
MetaBase UI Console(2)Docker on MySQL
2018-11-29 06:58 966MetaBase UI Console(2)Docker on ... -
AWS Lambda and Serverless Timeout
2018-09-20 01:20 644AWS Lambda and Serverless Timeo ... -
2018 WebSocket(1)Introduction
2018-03-20 01:22 11252018 WebSocket(1)Introduction ... -
2018 TypeScript Update(3)Introduction Basic Grammar
2018-03-08 03:08 6352018 TypeScript Update(3)Introd ... -
2018 TypeScript Update(2)Introduction Basic Grammar - Classes and Functions
2018-03-06 05:32 5902018 TypeScript Update(2)Introd ... -
2018 TypeScript Update(1)Introduction Basic Grammar - Types and Interface
2018-03-03 01:15 6242018 TypeScript Update(1)Introd ... -
Charts and Console(6)Paging
2018-03-01 00:12 601Charts and Console(6)Paging Th ... -
Vue.JS(3)Google Login
2018-02-14 04:53 1349Vue.JS(3)Google Login I just p ... -
Vue.JS(2)Monitor Water Console - ChartJS and Axios
2018-02-14 03:17 752Vue.JS(2)Monitor Water Console ... -
Vue.JS(1)Introduction and Basic Demo
2018-02-08 06:47 633Vue.JS(1)Introduction and Basic ... -
Charts and Console(5)Validation Form
2017-10-03 05:12 827Charts and Console(5)Validation ... -
Charts and Console(4)Display and Enhancement
2017-09-20 05:39 660Charts and Console(4)Display an ... -
Charts and Console(3)Auth and Login
2017-09-13 03:45 683Charts and Console(3)Auth and L ... -
Charts and Console(2)Login and Proxy
2017-08-31 05:39 895Charts and Console(2)Login and ... -
Charts and Console(1)UI Console and RESTful Client
2017-08-29 11:02 791Charts and Console(1)UI Console ... -
Blog Project(2)Express Backend API - istanbul - mocha - bunyan
2017-06-09 00:05 499Blog Project(2)Express Backend ... -
ReactJS(5)Composition vs Inheritance
2017-06-06 05:55 1136ReactJS(5)Composition vs Inheri ...
相关推荐
《ShaderX Vertex and Pixel Shader Tips and Tricks》是一本专注于计算机图形学中着色器技术的专业书籍。本书由Wolfgang F. Engel编辑,由Wordware Publishing, Inc.出版,并获得了美国国会图书馆的编目数据记录。...
"像素点pixel"在HTML5中主要涉及网页元素的尺寸单位、分辨率处理以及图像渲染等方面。在这个主题下,我们将深入探讨CSS(层叠样式表)和JavaScript在处理像素点中的应用。 首先,CSS是用于控制网页外观和布局的样式...
With vertex shaders for the programmable geometry pipeline and pixel shaders for the programmable pixel pipeline, the control over geometry and pixels was handed back to the developer....
谷歌pixel 3刷写第三方twrp3.6版本教程+工具 资源说明: 1----刷写第三方twrp的前提是手机要解锁bl先。请自行解锁bl先。 2----资源可以支持当前机型刷写第三方rec 3-----内含刷写资源和详细刷写教程步骤 4-----...
This book is intended for people that have some background in DirectX8 or DirectX9 programming and want to upgrade their knowledge to DirectX 10. At some point this book will be available on paper and...
Pixel Bender basics for Flex and AIR -- Sample files
Pixel Perfect Camera script gives more control over the camera size and enables pixel perfect rendering for pixel art Sprites and Canvas elements.
HTML5 Canvas Border Pixel Progressbar是一种使用HTML5 Canvas API创建的进度条效果,它将边界像素化,以展示进度。在本文中,我们将深入探讨HTML5 Canvas API,了解如何利用其特性构建这种独特的进度条。 首先,...
【标题】"pixel 破电信.zip" 指的是针对Pixel系列智能手机的一个特定软件更新或MOD,旨在使原本不支持中国电信网络的设备能够使用电信的4G/3G/2G服务。这个压缩包文件可能包含了一套修改过的系统固件或者基带文件,...
5. **USB Drivers**:允许电脑通过USB连接识别和控制Pixel 2的驱动程序。 要使用这些驱动,开发者通常会将它们集成到自定义的Android构建环境中,如使用AOSP(Android Open Source Project)源码。编译完成后,生成...
The slides and video for "Life of a Pixel" are now publically available. This talk is an introduction to Chromium's rendering pipeline. It traces all the steps from web content to displayed pixels, ...
标题 "HLSL-and-Pixel-Shaders-for-XAML-Developers_HLSL_" 指向的主题是关于在XAML开发中使用HLSL(High-Level Shader Language)和像素着色器的技术。HLSL是一种专门用于图形处理单元(GPU)编程的语言,尤其在...
标题"Cloacked-Pixel-Master"暗示我们可能在讨论一种与隐蔽像素或图像加密技术相关的话题。这种技术通常用于隐私保护、数据隐藏或者网络安全领域。描述中的内容是相同的,这可能意味着项目的核心就是"cloacked-pixel...
这个压缩包包含了一个名为“html5-canvas-pixel-image-master”的文件夹,我们可以推测这包含了实现该效果的所有源代码。 首先,我们要理解HTML5 Canvas的基本概念。Canvas是一个基于矢量图形的画布,通过...
灰度图像的每个像素只有一个亮度值,而不是RGB三原色分量。转换方法通常是将红色、绿色和蓝色分量的平均值作为新的像素值。 以下是一个简单的HLSL代码示例,展示了如何实现这一功能: ```hlsl float4 PS_Main...
这是使用 PixelCNN 解码器生成条件图像的 Tensorflow 实现,其引入了最初在像素周期性神经网络中提及的基于 PixelCNN 架构的门控 PixelCNN 模型。该模型可以基于标签或图像的潜在表示来相应地生成图像。图像也可以无...