从本地路径加载图像并在画布上绘制 [英] Load Image from local path and draw it on canvas
本文介绍了从本地路径加载图像并在画布上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在画布上绘制一个图像,其中图像源将由用户动态设置。我收到以下错误'不允许加载本地资源:file:/// D:/My%20Picsb.jpg'在尝试为图像设置src时。有没有办法从本地驱动器加载文件在画布上绘制它们?
I want to draw a image on canvas where the source for image will be set dynamically by user.I am getting following error 'Not allowed to load local resource: file:///D:/My%20Picsb.jpg' while trying to set src for image.Is there any way to load file from local drives to draw them on canvas?
var img = new Image();
img.onload = function () {
context.drawImage(img, 20, 20, 50, 50);
};
img.src = "D:\My Pics\tb.jpg";
推荐答案
JavaScript - 出于安全考虑 - 请勿让您访问本地计算机。您在浏览器内关闭(沙箱)...
JavaScript - for security reasons - don't let you access the local computer. You are closed inside the browser (sandbox)...
这篇关于从本地路径加载图像并在画布上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文