填充图像与其他图像javascript/html5
fill image with other image javascript/html5
我需要以下资源http://www.filmfans.cz/test/index2.html的帮助我不知道如何在点击样品后改变粉红色的颜色。我想做一些类似于下面的链接http://www.pixelbox.sk/fileadmin/Flash/cosmo_2.swf
这是我的代码<>之前
$(window).load(function(){
var width = $(window).width();
var height = $(window).height();
var c = document.getElementById("a");
var ctx = c.getContext("2d");
var can2 = document.createElement('canvas');
document.body.appendChild(can2)
can2.width = c.width;
can2.height= c.height;
var ctx2 = can2.getContext("2d");
var test= new Image();
test.src = "tux.png";
test.onload = function() {
ctx2.drawImage(test, 0, 0);
}
var img = new Image();
img.src = "2.png";
img.onload = function(){
ctx2.globalCompositeOperation = "source-in";
var pattern = ctx2.createPattern(img, "repeat");
ctx2.fillStyle=pattern;
ctx2.fillRect(0,0,300,300);
}
});
$(document).ready(function () {
$('.klik').click(function() {
var adresa = $(this).children('img').attr('src');
var canvas = document.getElementById("a");
canvas.width = canvas.width;//blanks the canvas
var c = canvas.getContext("2d");
var img = new Image();
img.src = adresa;
img.onload = function(){
var pattern = c.createPattern(img, "repeat");
//c.globalCompositeOperation = "source-in";
c.fillStyle=pattern;
c.fillRect(0,0,300,300);
}
// c.drawImage(img, 0, 0);
//}
//return false;
});
});
</code>
</pre>
之前问题解决了
使用第二个临时画布与source-in
是正确的想法:
ctx2.drawImage(test, 0, 0);
ctx2.globalCompositeOperation = 'source-in';
var ptrn = ctx2.createPattern(pattern,'repeat');
ctx2.fillStyle = ptrn;
ctx2.fillRect(0,0,300,300);
ctx.drawImage(can2,0,0)
生活的例子:http://jsfiddle.net/UcGrC/
相关文章:
- HTML5在画布中加载较小的图像并保存实际大小的图像
- 如何使用Javascript/Jquery/HTML5函数将HTML页面捕获为图像
- 如何将 html5 画布另存为窗口 8 Metro 应用程序中的图像文件
- 无法为HTML5中具有画布和图像的可拖动元素设置“拖动图像”
- 如何在windows 8 html5现代用户界面中显示没有背景的图像
- HTML5拖放-如何删除IE上的默认重影图像
- 实际参考和使用HTML5捕获的图像
- HTML5拖放新图像并替换Div中的现有图像
- 如何在MVC5中运行时在HTML5 Canvas中显示图像
- HTML5/JavaScript图像点击事件
- 更改HTML5拖放中的重影图像
- Html5画布使用JCanvasScript加载图像
- 将字节转换为用于在HTML5画布上绘制的图像
- html5 canvas toDataURL 返回空白图像
- 使用模式在 HTML5/JS 中绘制图像
- 单击时显示 Html5 画布图像
- 如何使用HTML5和AR在视频/图像上实时生成3d标记
- 如何用箭头键在画布上移动图像html5
- 使用在图像HTML5上绘制
- 在画布上绘制图像HTML5错误