【问题标题】:Add the image to canvas using html or php使用 html 或 php 将图像添加到画布
【发布时间】:2013-02-14 13:53:06
【问题描述】:

我尝试了很长时间如何仅将图像添加到 html 或 php 中的画布我得到了图像路径我需要将图像加载到 html 或 php 中的画布,我不需要通过 jquery 添加图像或 javascript

在 html 中我试试这个。

<canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;">
<img src="" alt="Resized Image" height="200px"     
width="200px"></canvas>

【问题讨论】:

    标签: html canvas image-loading


    【解决方案1】:

    有几种方法可以做到这一点。

    首先,通过在 css 中设置背景图像,有一种稍微有点 hackish 的方法,如下所示:

    <canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;background-image:url('path/to/your/image.ext')">
    </canvas>
    

    如果您只想显示图像,这会很好,但是,我假设您想实际操作它。在这种情况下,请查看this answer

    【讨论】:

    • 谢谢。但如果我这样设置我无法编辑图像,我尝试制作一个画布图像编辑器。在画布中加载图像的任何其他方式
    • 查看我在答案末尾给出的链接 - 该问题的接受答案提供了工作 JavaScript 代码来做你想做的事。在 HTML5 中,要真正使用 canvas 标签,您需要使用 javascript。
    • 这是在画布中添加图像的唯一方法。
    • 是的,根据一些消息来源:w3schools - “HTML5 元素用于通过脚本(通常是 JavaScript)动态绘制图形。”,wikipedia,和html5canvastutorials
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 2017-09-23
    • 2011-10-20
    • 2020-04-30
    • 2015-06-25
    • 1970-01-01
    相关资源
    最近更新 更多