HTML5 Canvas border Style inconsistencies when drawing rectangles

Source: Internet
Author: User

These two days need to use a colleague HTML5 drawing, found inside the function of the rectangle painted rectangular style inconsistent problem, finally I through some exclusion law found the crux of the problem, now share to everyone.

First enclose the code of the HTML5 rectangle:

Copy Code code as follows:
<canvas id= "MyCanvas" width= "578" height= "></canvas>"
<script>
var canvas = document.getElementById (' MyCanvas ');
var context = Canvas.getcontext (' 2d ');

Context.beginpath ();

Context.rect (188.0, 50, 200, 100.375);
Context.fillstyle = ' white ';
Context.fill ();
Context.linewidth = 1;
Context.strokestyle = ' red ';
Context.stroke ();
</script>


You will find that the following border style is not the same, obviously the bottom is very thin. and the colors are slightly different.

After modifying Context.rect (188.0, 50, 200, 100.375) to Context.rect (188.0, 50, 200, 100), the pattern was found to be identical.
This explains: When drawing a rectangle, if the parameters inside are not integers, it is easy to cause a border problem, so we recommend that you take the whole after the use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.