Are Paths the most efficient way to draw changing shapes?

旧巷老猫 提交于 2020-01-15 11:24:59

问题


The app I'm building has to draw around 400 quadrilateral shapes onto the screen with a fluent frame rate. The shapes 255 permutations and are drawn rotated anywhere from 0-360 degrees. I don't think pre-rendering them would efficient, given the amount of memory it would take (I could be wrong though). They also have a 24-bit color range. Right now I'm drawing them with paths and all the rotation and translation is handled by the function generating the values. Although this implementation is working (all be it at a low frame rate of like 25), I just feel like there's a more efficient way of doing it. To be honest, openGL and java looks quite confusing, but if it's the only option then I would man up and learn it.

TL;DR Is this code the most efficient for constantly changing shapes?

        void quad(Canvas canvas,Paint paint, float x1,float y1, float x2,float y2, float x3,float y3,float x4,float y4,  float xoff, float yoff, int color){
        float[] hsvc = { map(color,0,100,0,360),.8f,1};
        paint.setColor(Color.HSVToColor(hsvc));
        Path path = new Path();
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        path.lineTo(x4, y4);
        path.close();
        path.offset(xoff, yoff);
        canvas.drawPath(path, paint);
    }

Thank you!


回答1:


What are your permutations ans how do you rotate the paths?

As Path seems to be mutable in Android, you might try to reuse an instance and see if it gives you better results (using Path.reset() for instance).




回答2:


A bit of followup:

Using Android's Canvas system, Paths were the most efficient way that I could find. I ended up using opengl which is a much better alternative.



来源:https://stackoverflow.com/questions/9022766/are-paths-the-most-efficient-way-to-draw-changing-shapes

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