将多个图像从一个画布拖放到html5中的另一画布 [英] drag and drop multiple image from one canvas to another canvas in html5

查看:93
本文介绍了将多个图像从一个画布拖放到html5中的另一画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天,我遇到了问题.实际上,我是HTML5的新手,如今,我尝试将多个图像从一个画布拖放到另一个画布上,反之亦然.我有旅行多个链接,但无济于事,因为该链接只有一个画布,并且在该画布中拖放.像下面的链接
http://simonsarris.com/blog/225-canvas-selecting-resizing-shape [ ^ ]
但我想要在HTML5中这样
http://www.w3schools.com/html/html5_draganddrop.asp [解决方案


These days i''m suffering from a problem. Actually i''m new in HTML5, and these days i''m try to do drag and drop multiple images from one canvas to another canvas vice-versa. I have travel multiple links but that not help me, because that links have only one canvas and drag and drop within that canvas. like below links
http://simonsarris.com/blog/225-canvas-selecting-resizing-shape[^]
but i want like this in HTML5
http://www.w3schools.com/html/html5_draganddrop.asp[^]

Thanks

解决方案



The short & simple answer is: you can''t.

The qualified answer is: The thing with the canvas element is that it holds a number of different state variables (stroke color, width, fill color, and other assorted styles, positions and transforms) as well as the pixels that it contains. That is to say, it doesn''t keep track of any elements drawn to it.

The html5 drag/drop demo moves html elements around. You could drag and drop the whole canvas, but not the objects that have been drawn to it. Imagine drawing some text in a bitmap editor over a photo background. You can''t just copy the text any more - there is no ''text'' - there is only a series of pixels that are coloured in a way that represents text.

That''s the state of affairs with the canvas.

However, if you were to maintain a list yourself of which objects were drawn to the canvas and where, _then_ you could handle mouse events on the canvas and check your list of coords/objects to see if the cursor is above any of them. You could then ''select'' the ''object'' and allow dragging to another canvas. This would then remove the object from your list for the first canvas, redraw that canvas and then insert it into the list of objects to be drawn onto the second canvas, before updating that canvas too.


这篇关于将多个图像从一个画布拖放到html5中的另一画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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