Android: Refresh bitmap with new data
<p>I am trying to create a 15fps "bitmap video" of random pixel colors.  The following code displays one bitmap correctly, however does not update/refresh the image with a new random one.  Can anyone please help me figure out why?</p>

<pre><code>public class ViewThread extends Thread {
    private SurfaceHolder mHolder;
    private Panel mPanel;
    private boolean mRun = false;

    public ViewThread( Panel panel) {
        mPanel = panel;
        mHolder = mPanel.getHolder();
    }

    public void setRunning(boolean run) {
        mRun = run;
    }

    @Override
    public void run() {
        Canvas canvas = null;
        while (mRun) {
            canvas = mHolder.lockCanvas();
            if (canvas != null) {
                mPanel.doDraw(canvas);
                mHolder.unlockCanvasAndPost(canvas);
            }
        }
    }
}

public class Panel extends SurfaceView implements SurfaceHolder.Callback {
    private ViewThread mThread;
    private Bitmap mBitmap;
    private int[]   mcolors;

    public Panel(Context context) {
        super(context);
        init();
    } 

    private void init() {
        getHolder().addCallback(this);
        mThread = new ViewThread(this);

        // create a graphic
        mcolors = colorMap(); 
        int[] colors = mcolors; 
        mBitmap = Bitmap.createBitmap(colors, 64, 64, Bitmap.Config.ARGB_8888);  
        mBitmap = Bitmap.createScaledBitmap(mBitmap, 256, 256, false);
    }

    protected void doDraw(Canvas canvas) {
        canvas.drawColor(Color.BLACK);
        canvas.drawBitmap(mBitmap, 8, 8, null);
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    //@Override
    public void surfaceCreated(SurfaceHolder holder) {
        if (!mThread.isAlive()) {
            mThread = new ViewThread(this);
            mThread.setRunning(true);
            mThread.start();
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
         if (mThread.isAlive()) {
             mThread.setRunning(false);
         }
    }
}

private static int[] colorMap() {

     int[] ltable = { 0xff000000, 0xff00000f, 0xff00001e, 0xff00002d, 0xff00003c, 0xff00004b, 
                    0xff00005a, 0xff000069, 0xff000078, 0xff000087, 0xff000096, 0xff0000a5, 
                    0xff0000b4, 0xff0000c3, 0xff0000d2, 0xff0000e1, 0xff0000f0, 0xff0000ff,
                    0xff0f00ff, 0xff1e00ff, 0xff2d00ff, 0xff3c00ff, 0xff4b00ff, 0xff5a00ff,
                    0xff6900ff, 0xff7800ff, 0xff8700ff, 0xff9600ff, 0xffa500ff, 0xffb400ff, 
                    0xffc300ff, 0xffd200ff, 0xffe100ff, 0xfff000ff, 0xffff00ff, 0xffff00f0,
                    0xffff00e1, 0xffff00d2, 0xffff00c3, 0xffff00b4, 0xffff00a5, 0xffff0096,
                    0xffff0087, 0xffff0078, 0xffff0069, 0xffff005a, 0xffff004b, 0xffff003c,
                    0xffff002d, 0xffff001e, 0xffff000f, 0xffff0000 };

     int[] mcolors = new int[4096];
     Random rand = new Random();

     for(int i=0; i &lt; 4096; i++)
     {
         int num = rand.nextInt(52); 
         mcolors[i] = ltable[num];
     }

     return mcolors;
}
</code></pre>

<p>}</p>
