问题:华为鸿蒙HarmonyOS中SurfaceProvider无法绘制图形,是什么原因呢?
问题追加: 代码如下: public class MySurfaceProvider extends SurfaceProvider implements SurfaceOps.Callback { SurfaceOps surfaceOps; Paint paint; public MySurfaceProvider(Context context) { super(context); surfaceOps = this.getSurfaceOps().get(); surfaceOps.addCallback(this); paint = new Paint(); paint.setColor(Color.YELLOW); paint.setTextSize(100); } void drawing() { Canvas canvas = surfaceOps.lockCanvas(); canvas.drawText(paint, "hello HarmonyOS", 100, 100); surfaceOps.unlockCanvasAndPost(canvas); } @Override public void surfaceCreated(SurfaceOps surfaceOps) { drawing(); } @Override public void surfaceChanged(SurfaceOps surfaceOps, int i, int i1, int i2) { drawing(); } @Override public void surfaceDestroyed(SurfaceOps surfaceOps) { } unlockCanvasAndPost在官方文档里的说明是释放一个Canvas并把它显示到屏幕上:
不过却怎么都绘制不出来文本。 除非用DrawTask接口的onDraw方法,但是那样就和普通的Component组件一样了,还要这个SurfaceProvider类有什么用?
回答: 方法没有什么不对,产生该问题的真正原因是HarmonyOS中SurfaceProvider目前还不支持绘制图形。 |