0

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);
        }
    }
}

c0deBeastx
  • 33
  • 1
  • 8
  • Can you confirm that your draw code is running? The code posted above looks like it wouldn't do anything if `run()` were called right away, because it would happen before `surfaceCreated()`, so the `isValid()` test would fail. After the failure the thread exits and never tries again. If you add some logging you should be able to see if that's the case. – fadden Mar 16 '14 at 16:51
  • No dude .. i don't get any error . That is why i did post this question .!!! If so can u get me a sample code ..!! – c0deBeastx Mar 16 '14 at 17:44

0 Answers0