简体   繁体   English

使用自由形式绘制图像 <canvas> 和javascript

[英]Freeform drawing over an image using <canvas> and javascript

I have been trying to find a good resource to point me in the correct direction and I'd really like someone to help me in this regard. 我一直在努力找到一个很好的资源来指出我正确的方向,我真的希望有人在这方面帮助我。

I'm developing an app that uses phonegap, js and html5. 我正在开发一个使用phonegap,js和html5的应用程序。 One component of this app is to have an image that can be overlayed with freeform scribbles. 这个应用程序的一个组成部分是拥有一个可以覆盖自由形式涂鸦的图像。

I'm not sure if its the canvas object I should be using and if so how do I go about implementing a drawing solution. 我不确定它是否应该使用它的画布对象,如果是,我该如何实现绘图解决方案。

You create a and position it absolute over image. 您创建一个并将其置于图像上的绝对位置。

can have transparent pixels (alpha=1.0) and those pixels will display the underlying image. 可以有透明像素(alpha = 1.0),这些像素将显示底层图像。

Then you flip pixels accordingly your scribbling to black etc. You need to listen to touch events, transform their coordinates to coordinates and then use canvas.getContext() draw operation to manipulate pixels hitting in those coordinates. 然后你相​​应地翻转像素你的涂鸦到黑色等。你需要听取触摸事件,将它们的坐标转换为坐标,然后使用canvas.getContext()绘制操作来操纵在这些坐标中击中的像素。

If you need further assistance please ask individual questions for each part as a complete solution would be longish source code and outside the scope of simply answering the questions. 如果您需要进一步的帮助,请询问每个部分的个别问题,因为完整的解决方案将是冗长的源代码,并且不在简单回答问题的范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM