如何更改fabric.Image对象属性src的图像? [英] How to change the image of the fabric.Image object attribute src?
本文介绍了如何更改fabric.Image对象属性src的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果已经制作了动画,如何更改fabric.Image
对象属性src的图像?
How can I change the image of the fabric.Image
object attribute src, if I have already made an animation?
推荐答案
您可以使用.setElement()
更改图像.
例如,假设您有一个名为myFabricObect
的fabricJS图像对象.
For example, let's say you have a fabricJS image object called myFabricObect
.
然后,如果页面上有html图像元素<img id="newImage">
,则可以使用"newImage"
加载myFabricObject
,如下所示:
Then, if you have an html image element <img id="newImage">
on your page, you can load your myFabricObject
with the "newImage"
like this:
myFabricObject.setElement(document.getElementById("newImage"));
您还可以创建一个JavaScript Image()
并将其分配给myFabricObject
:
You could also create a javascript Image()
and assign that to myFabricObject
:
var img=new Image();
img.onload=function(){
myFabricObject.setElement(img);
}
img.src="myNewImage.png";
这篇关于如何更改fabric.Image对象属性src的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文