Simple graphics API with transparency, polygons, reading image pixels?

一笑奈何 提交于 2019-12-12 21:03:29

问题


I need a simple graphics library that supports the following functionality:

  1. Ability to draw polygons (not just rectangles!) with RGBA colors (i.e., partially transparent),
  2. Ability to load bitmap images,
  3. Ability to read current color of pixel in a given coordinate.

Ideally using JavaScript or Python.

Seems like HTML 5 Canvas can handle #2 and #3 but not #1, whereas SVG can handle #1 and #2 but not #3. Am I missing something (about either of these two)? Or are there other alternatives?


回答1:


PyGame can do all of those things. OTOH, I don't think it embeds into a GUI too well.




回答2:


I ended up going with Canvas. The "secret" of polygons is using paths. Thanks, "tur1ng"!




回答3:


GameJs does that and more - it's similar to the mentioned PyGame.

http://gamejs.org

Ability to draw polygons (not just rectangles!) with RGBA colors (i.e., partially transparent),

gamejs.draw.polygon (surface, color, pointlist, width)

Transparent colors can be defined as 'rgba(50, 50, 50, 0.1)' (last is alpha)

http://docs.gamejs.org/gamejs/draw/#polygon

Ability to load bitmap images,

var surface = gamejs.image.load('images/foo.png')

http://docs.gamejs.org/gamejs/image/

Ability to read current color of pixel in a given coordinate.

// a surface array is a special DOM canvas array
// that is superfast for per pixel access / manipulation

var srfArray = new SurfaceArray(display);
srfArray.set(50, 100, [255, 0, 0, 100]);
srfArray.get(20, 30);

http://docs.gamejs.org/gamejs/surfacearray/




回答4:


I voted for PyGame, but I would also like to point out that the new QT graphics library seems quite capable. I have not used PyQT with QT4 yet, but I really like PyQT development with QT3.




回答5:


maybe Raphael - http://raphaeljs.com/reference.html



来源:https://stackoverflow.com/questions/3021514/simple-graphics-api-with-transparency-polygons-reading-image-pixels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!