javascript – 替换fabric.js调整大小并旋转控件与自定义图像?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 替换fabric.js调整大小并旋转控件与自定义图像?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2116字,纯文字阅读大概需要4分钟。
内容图文
![javascript – 替换fabric.js调整大小并旋转控件与自定义图像?](/upload/InfoBanner/zyjiaocheng/752/0fdb9b1863a04742a831064c5eb377ab.jpg)
我正在寻找如何替换fabric.js调整大小并使用自定义图像旋转矩形的示例….有人这样做过吗?
谢谢.
解决方法:
您可以通过覆盖原型来实现:
var topLeftImage = new Image();
topLeftImage.src = 'images/tl.png';
var topRightImage = new Image();
topRightImage.src = 'images/tr.png';
var bottomRightImage = new Image();
bottomRightImage.src = 'images/br.png';
//Warning I modified some other things here as well, please copy this from the sources and modify it then
fabric.Object.prototype.drawCorners = function(ctx) {
if (!this.hasControls) return;
var size = this.cornersize,
size2 = size / 2,
strokeWidth2 = this.strokeWidth / 2,
left = -(this.width / 2),
top = -(this.height / 2),
_left,
_top,
sizeX = size / this.scaleX,
sizeY = size / this.scaleY,
paddingX = this.padding / this.scaleX,
paddingY = this.padding / this.scaleY,
scaleOffsetY = size2 / this.scaleY,
scaleOffsetX = size2 / this.scaleX,
scaleOffsetSizeX = (size2 - size) / this.scaleX,
scaleOffsetSizeY = (size2 - size) / this.scaleY,
height = this.height,
width = this.width;
ctx.save();
ctx.lineWidth = 1 / Math.max(this.scaleX, this.scaleY);
ctx.globalAlpha = 1; //this.isMoving ? this.borderOpacityWhenMoving : 1;
ctx.strokeStyle = ctx.fillStyle = '#333333';
// top-left
_left = left - scaleOffsetX - strokeWidth2 - paddingX;
_top = top - scaleOffsetY - strokeWidth2 - paddingY;
ctx.clearRect(_left, _top, sizeX, sizeY);
ctx.drawImage(topLeftImage, _left, _top, sizeX, sizeY);
// top-right
_left = left + width - scaleOffsetX + strokeWidth2 + paddingX;
_top = top - scaleOffsetY - strokeWidth2 - paddingY;
ctx.clearRect(_left, _top, sizeX, sizeY);
ctx.drawImage(topRightImage, _left, _top, sizeX, sizeY);
// bottom-left
_left = left - scaleOffsetX - strokeWidth2 - paddingX;
_top = top + height + scaleOffsetSizeY + strokeWidth2 + paddingY;
ctx.clearRect(_left, _top, sizeX, sizeY);
ctx.strokeRect(_left, _top, sizeX, sizeY);
// bottom-right
_left = left + width + scaleOffsetSizeX + strokeWidth2 + paddingX;
_top = top + height + scaleOffsetSizeY + strokeWidth2 + paddingY;
ctx.clearRect(_left, _top, sizeX, sizeY);
ctx.drawImage(bottomRightImage, _left, _top, sizeX, sizeY);
ctx.restore();
return this;
};
内容总结
以上是互联网集市为您收集整理的javascript – 替换fabric.js调整大小并旋转控件与自定义图像?全部内容,希望文章能够帮你解决javascript – 替换fabric.js调整大小并旋转控件与自定义图像?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。