Drawing using the Surfaceview creates blank screen

廉价感情. 提交于 2019-12-13 04:29:15

问题


I am creating a mind game based upon pictures . So i have to add a Matrices of images . I m using the surface view to run my thread so as to draw the content on to the screen by locking the screen to the canvas and bitmaps will be drawn inside the canvas . Here is my code . There is no error but a blank screen is displayed . What should i do ? Get me a solution

public class InsideSurface extends SurfaceView implements Runnable {

    SurfaceHolder ourHolder;

    int start;//starting position to draw
    int im_wd;//width of the bitmap
    int im_ht;//height of the bitmap
    int i = 0;

    public InsideSurface(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        getStart();
        ourHolder = getHolder();
    }

    private void getStart() {
        // TODO Auto-generated method stub
        start = (width % 100) / 2;
        im_wd = (width - (width % 100)) / 4;
        im_ht = (width - (width % 100)) / 4;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        Bitmap bmp;
        if (!ourHolder.getSurface().isValid()) {

            Canvas canvas = ourHolder.lockCanvas();
            canvas.drawARGB(20, 50, 60, 120);
            for (int x = 0, tempy = start; x < 4; x++, tempy += im_ht) {
                for (int y = 0, tempx = start; y < 4; y++, tempx += im_wd) {
                    bmp = BitmapFactory.decodeResource(getResources(),
                            image[i++]);
                    canvas.drawBitmap(bmp, tempx, tempy, null);
                }
            }

            ourHolder.unlockCanvasAndPost(canvas);
        }
    }
}

来源:https://stackoverflow.com/questions/22428689/drawing-using-the-surfaceview-creates-blank-screen

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