本文介绍了如何在SurfaceView上绘制图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android.我在主类中添加了onTouchEvent,当我切换到SurfaceView时,它可以正常工作.我需要在上面画一些图形.

Android. I have added onTouchEvent in my main class and it works ok when I switched to SurfaceView. I need to draw some graphics on it.

public boolean onTouchEvent(MotionEvent event) {
    if(connected)
    {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        GraphicObject graphic = new GraphicObject(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
        graphic.getCoordinates().setX((int) event.getX() - graphic.getGraphic().getWidth() / 2);
        graphic.getCoordinates().setY((int) event.getY() - graphic.getGraphic().getHeight() / 2);
        _graphics.add(graphic);
        initial_x = event.getX();
        initial_y = event.getY();

        Canvas canvas = new Canvas();
        canvas.drawColor(Color.BLACK);

        Bitmap bitmap;
        GraphicObject.Coordinates coords;
            bitmap = graphic.getGraphic();
            coords = graphic.getCoordinates();
            canvas.drawBitmap(bitmap, 50, 50, null);
    }
    }
    return super.onTouchEvent(event);
}


没有画任何东西.请提供帮助.


Does''nt draw anything. Please help.

推荐答案


这篇关于如何在SurfaceView上绘制图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:44