Javascript:使用绝对路径设置img src [英] Javascript: Setting img src with absolute path

查看:153
本文介绍了Javascript:使用绝对路径设置img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图手动设置img src到文件系统上的路径,然后我想在画布上绘制该图像。我使用:

I am trying to manually set the img src to a path on the filesystem, and then I want to draw that image on a canvas. I am using:

    var curr_canv = document.getElementById('c_main').getContext('2d');
    var img = new Image();

    img.width = 525;
    img.height = 400;

    img.src = "..\AAAA\BBBB\CCCC\myimage.jpg";

    curr_canv.drawImage(img,0,0);

但是我没有在画布上绘制。任何想法?

But nothing is drawn on the canvas after I do this. Any thoughts?

推荐答案

您需要在网络服务器中设置绝对路径 br>
浏览器中的JavaScript无法访问任何文件系统。

You need to set the path to an absolute path within your webserver.
Javascript in the browser has no access to any filesystem.

这篇关于Javascript:使用绝对路径设置img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆