简体   繁体   English

为什么在画布中创建的矩形不遵循所述的宽度n高度?

[英]Why the rect created in the canvas doesn't follow the width n height stated?

I have a div, inside the div I have a canvas and I need to create a rect in the canvas.. 我有一个div,在div内有一个画布,我需要在画布中创建一个rect。

this.canvas = {
            innerElement: TBE.CreateRectCanvasElement (Element.config.displayWidth, Element.config.displayHeight)
        };
    this.canvas.innerElement.style.border = '1px solid black';
    this.innerElementCtx = this.canvas.innerElement.getContext("2d");
    this.innerElementCtx.fillStyle = '#3ac6e5';
    this.innerElementCtx.fillRect(50, 50, 100, 100);

but the rect turns out to be not 50px n 50px away from the top n left and the height is much greater than the width... Why? 但是,直到原来的左边是np 50px,并且高度比宽度大得多......为什么?

http://jsfiddle.net/dpQ64/3/ http://jsfiddle.net/dpQ64/3/

It is because you did not set the width and height of the <canvas> in the HTML. 这是因为您没有在HTML中设置<canvas>的宽度和高度。
It is default to be in 1:1 ratio, and since you make it 100:300 in CSS, its width shrinks by 1/3 . 它默认为1:1比例,因为你在CSS中使它为100:300 ,它的宽度缩小了1/3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM