3
A
回答
10
您可以通過重寫原型是這樣做的:
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;
};
+2
您好@Alexander Kludt您可以請更多地解釋您的代碼,在哪裏添加此代碼或在織物庫中重寫它。請指教 –
相關問題
- 1. 旋轉並調整圖像大小+ iPhone
- 2. 旋轉圖像*無*調整大小
- 3. 調整大小的自定義控件
- 4. 調整大小並使用PHP替換圖像
- 5. 調整大小並使用PHP轉換圖像
- 6. 將html轉換爲pdf並自動旋轉並調整大頁面大小
- 7. 圖像大小調整和控件佈局轉換
- 8. 自動調整圖像大小並縮小文件大小
- 9. 使用ImageResizer調整圖像的大小/轉換圖像
- 10. 如何旋轉圖像並同時調整大小
- 11. 自定義控制調整大小C#
- 12. Bootstrap-3旋轉木馬中的圖像自動調整大小
- 13. 自定義UIView旋轉時調整大小
- 14. 圖像調整大小時,Codeigniter圖像旋轉
- 15. 旋轉也調整大小?
- 16. jquery插件的旋轉和調整大小圖像
- 17. fabric.js:使用Image.set()調整圖像大小是否會降低圖像質量?
- 18. 調整翻轉和旋轉的圖像的大小
- 19. C#:自定義控件正在調整自己的大小
- 20. 調整大小並轉換圖像中的R爲灰度
- 21. React Native - 調整圖像大小並將其轉換爲base64
- 22. php圖像調整大小並在上傳時轉換爲jpg
- 23. 使用調整大小.SVG圖像「轉換」功能產生
- 24. 控制調整大小時調整圖像的大小c#
- 25. 用404圖像替換無效圖像url,用自定義大小
- 26. 調整圖像大小,並用PHP
- 27. 用jquery自動調整圖像大小
- 28. 啓用自動圖像調整大小
- 29. 合併圖像並調整其大小
- 30. 在屏幕上自動調整圖像大小調整大小
這是不是現在很容易,但通過在每個頂部更改源代碼或顯示圖像控制與此類似演示 - HTTP: //fabricjs.com/interaction-with-objects-outside-canvas/ – kangax
這個問題是從2012年開始的,如果你通過谷歌來到這裏,你可能也想看看這個更近的回答:http://stackoverflow.com/a/24533063/29182 – Ziggy