Canvas canvas = holder.lockCanvas(); canvas.drawRGB(255, 0, 0); holder.unlockCanvasAndPost(canvas);
第一行,鎖定Surface用于渲染并返回一個可用的Canvas
創新互聯建站長期為成百上千家客戶提供的網站建設服務,團隊從業經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態環境。為韶山企業提供專業的網站設計、成都網站建設,韶山網站改版等技術服務。擁有10年豐富建站經驗和眾多成功案例,為您定制開發。
第二行,解鎖Surface并確保通過Canvas進行繪制的內容可顯示到屏幕上
例子:
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(); } } } } }
當前文章:SurfaceView連續渲染SurfaceHolder Canvas
轉載源于:http://m.2m8n56k.cn/article30/iesdso.html
成都網站建設公司_創新互聯,為您提供網頁設計公司、域名注冊、品牌網站建設、用戶體驗、企業建站、面包屑導航
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯