使用jQuery在画布中选择图像 [英] Select image within canvas with jQuery

查看:119
本文介绍了使用jQuery在画布中选择图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JavaScript代码:

I have following JavaScript code:

var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
var img = new Image;
var x;
img.onload = function(){ ctx.drawImage(img,0,0); };
img.src='img.svg';

执行完以上代码后,我想使用jQuery选择SVG图像.为此,我编写了以下代码$('svg'),但这不起作用.

After execution of the above code I would like to select the SVG-image with jQuery. To do this I wrote following code $('svg'), but this doesn't work.

有人可以帮助我,以便我选择图像吗?

Can somebody help me so that I can select the image?

非常感谢您的帮助!

推荐答案

画布只是包含图像数据的位图,没有诸如对象之类的内置抽象概念.您可以做的是在画布上写入和读取.即,只要不将不安全的(即来自其他域的)不写到画布上即可.不幸的是,在将SVG写入/绘制到画布上时,错误地认为这是不安全的内容,您将无法再读取位图.

The canvas is just a bitmap containing image data, there are no built-in abstract concepts such as objects. What you can do is write to and read from the canvas. That is, as long as no unsecure (i.e. from other domains) are written to the canvas. Unfortunately when writing/drawing SVG to the canvas it's faulty considered to be unsecure content and you will no longer be able to read the bitmap.

这篇关于使用jQuery在画布中选择图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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