有没有 Fabric.JS 向导?我已经进行了充分的研究,但似乎找不到如何将图像添加到 fabric.JS 画布的解释。
用户流程: a) 用户从输入文件类型按钮上传图像。 b) 一旦他们从计算机中选择了图像,我希望将其放置到用户的画布中。
到目前为止,我已经将图像存储到一个表达式中,以下是我的代码:
如果你还没有猜到,我正在使用MEAN技术栈。即Mongoose、Express、Angular和Node。
变量imageSource是存储图像的位置。我已经阅读了这篇文章,其中提到了将图像压缩为结果并将其传递给fabric.Image对象的方法。有没有人做过类似的事情,并能够帮助我呢?
谢谢提前。
****更新**** 指令定义了canvas变量:
用户流程: a) 用户从输入文件类型按钮上传图像。 b) 一旦他们从计算机中选择了图像,我希望将其放置到用户的画布中。
到目前为止,我已经将图像存储到一个表达式中,以下是我的代码:
scope.setFile = function(element) {
scope.currentFile = element.files[0];
var reader = new FileReader();
/**
*
*/
reader.onload = function(event) {
// This stores the image to scope
scope.imageSource = event.target.result;
scope.$apply();
};
// when the file is read it triggers the onload event above.
reader.readAsDataURL(element.files[0]);
};
我的HTML/Angular:
<label class="app-file-input button">
<i class="icon-enter"></i>
<input type="file"
id="trigger"
onchange="angular.element(this).scope().setFile(this)"
accept="image/*">
</label>
如果你还没有猜到,我正在使用MEAN技术栈。即Mongoose、Express、Angular和Node。
变量imageSource是存储图像的位置。我已经阅读了这篇文章,其中提到了将图像压缩为结果并将其传递给fabric.Image对象的方法。有没有人做过类似的事情,并能够帮助我呢?
谢谢提前。
****更新**** 指令定义了canvas变量:
var canvas = new fabric.Canvas(attrs.id, {
isDrawingMode: true
});