安卓:帆布VS的OpenGL [英] Android: Canvas vs OpenGL

查看:158
本文介绍了安卓:帆布VS的OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绘图应用程序,用户可以绘制线条用他们的手指,调整颜色,厚度等,由于用户是借鉴,我从 MotionEvent <转换集结X / Y点/ code>进入 SVG路径,以及创造的Android路径的,然后绘制了Android路径的屏幕通过一个画布,并承诺SVG路径的到应用程序的数据库。

I have a drawing app where the user can draw lines with their finger, adjust the color, thickness, etc. As the user is drawing, I am converting the massed X/Y points from MotionEvent into SVG Paths, as well as creating Android Path's and then drawing the Android Path's to the screen via a Canvas, and committing the SVG Path's to the app's database.

我下面的<一个使用的模型href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html">FingerPaint,在该正在进行中画线在飞行中被重复调用无效()(因此,的OnDraw()),一旦该行已完成,并开始了新的生产线,在previous线(S)的绘制的OnDraw()从底层画布 位图,与在建行再产生重复再画。

I am following the model used in FingerPaint, in that the 'in progress' lines are drawn on the fly by repeated calls to invalidate() (and thus, onDraw()), and once the line is complete and a new line is started, the previous line(s) are drawn in onDraw() from the underlying Canvas Bitmap, with in progress lines again generating repeated re-draws.

这工作正常,在这个应用程序 - 直到你开始旋转底层位图来弥补设备旋转,配套能力'放大'的绘图表面,从而有规模的基本位图等,因此,例如,与设备旋转和拉伸缩放,当用户图纸,我们需要缩放和旋转我们的位图中的OnDraw(),这绝对是爬行。

This works fine in this application - until you start rotating the underlying Bitmap to compensate for device rotation, supporting the ability to 'zoom in' on the drawing surface and thus having to scale the underlying Bitmap, etc. So for example, with the device rotated and the drawing scaled in, when the user is drawing, we need to scale AND rotate our Bitmap in onDraw(), and this is absolutely crawling.

我看了 SurfaceView ,但因为这仍然使用相同的画布机制,我不知道我会看到明显的改善......所以我的思想转向的OpenGL。我已阅读的地方,OpenGL的可以做旋转和缩放本质上是自由,甚至看到传闻(第三点)的画布可能消失在未来的版本中。

I've looked at a SurfaceView, but as this still uses the same Canvas mechanism, I'm not sure I'll see noticeable improvement... so my thoughts turn to OpenGL. I have read somewhere that OpenGL can do rotations and scaling essentially 'for free', and even seen rumors (third comment) that Canvas may be disappearing in future versions.

从本质上讲,我有点卡住了画布和OpenGL解决方案之间的...我有一个2D绘图应用程序,似乎符合画布模式完全当一个状态,因为有没有不断重新抽奖事情就像一场游戏(例如当用户不拉我不需要任何重画),但是当用户是借鉴,我需要必要的最大性能做一些日益复杂的东西表面...

Essentially, I am a little stuck between the Canvas and OpenGL solutions... I have a 2D drawing app that seems to fit the Canvas model perfectly when in one state, as there are not constant re-draws going on like a game (for instance when the user is not drawing I don't need any re-drawing), but when the user IS drawing, I need the maximum performance necessary to do some increasingly complex things with the surface...

欢迎任何想法,指针和建议。

Would welcome any thoughts, pointers and suggestions.

推荐答案

OpenGL的将是能够处理旋转和轻松扩展。

OpenGL would be able to handle the rotations and scaling easily.

老实说,你可能需要学习很多的OpenGL要做到这一点,特别是涉及到的主题:

Honestly, you would probably need to learn a lot of OpenGL to do this, specifically related to the topics of:

  • 几何
  • 照明(或只是禁用它)
  • 在采摘(选择几何图形绘制就可以了)
  • 像素地图
  • 纹理映射
  • 纹理映射

此外,学习OpenGL进行,这可能是矫枉过正,你将不得不pretty的擅长,使之有效。

Also, learning OpenGL for this might be overkill, and you would have to be pretty good at it to make it efficient.

相反,我会建议使用内置于OpenGL之上的游戏库中的图形组件,例如:

Instead, I would recommend using the graphic components of a game library built on top of openGL, such as:

  • Cocos2d
  • libgdx
  • any of the engines listed here

这篇关于安卓:帆布VS的OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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