您好,登錄后才能下訂單哦!
Canvas canvas = holder.lockCanvas(); canvas.drawRGB(255, 0, 0); holder.unlockCanvasAndPost(canvas);
第一行,鎖定Surface用于渲染并返回一個可用的Canvas
第二行,解鎖Surface并確保通過Canvas進行繪制的內(nèi)容可顯示到屏幕上
例子:
import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.view.Menu; import android.view.SurfaceHolder; import android.view.SurfaceView; public class MainActivity extends Activity { FastRenderView renderView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); renderView = new FastRenderView(this); setContentView(renderView); } protected void onResume() {//重載 super.onResume(); renderView.resume(); } class FastRenderView extends SurfaceView implements Runnable { Thread renderThread = null; SurfaceHolder holder = null; volatile boolean running = false; public FastRenderView(Context context) { super(context); holder = getHolder(); } public void resume()//自定義 { running = true; renderThread.start(); } public void run() { while(running) { if(!holder.getSurface().isValid()) continue; Canvas canvas = holder.lockCanvas(); canvas.drawRGB(255, 0, 0); holder.unlockCanvasAndPost(canvas); } } public void pause()//自定義 { running = false; while(true) { try { renderThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。