新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > Android 的 SurfaceView 雙緩沖應用

        Android 的 SurfaceView 雙緩沖應用

        作者: 時間:2016-10-08 來源:網絡 收藏

        075 int index = 0;

        本文引用地址:http://www.104case.com/article/201610/305442.htm

        076 try {

        077 index = field.getInt(R.drawable.class);

        078 } catch (IllegalArgumentException e) {

        079 // TODO Auto-generated catch block

        080 e.printStackTrace();

        081 } catch (IllegalAccessException e) {

        082 // TODO Auto-generated catch block

        083 e.printStackTrace();

        084 }

        085 // 保存圖片ID

        086 imgList.add(index);

        087 }

        088 }

        089 // 取得圖像大小

        090 Bitmap bmImg = BitmapFactory.decodeResource(getResources(),

        091 imgList.get(0));

        092 imgWidth = bmImg.getWidth();

        093 imgHeight = bmImg.getHeight();

        094 }

        095

        096 @Override

        097 public void surfaceDestroyed(SurfaceHolder holder) {

        098 Log.i(Surface:, Destroy);

        099

        100 }

        101

        102 }

        103

        104 /**

        105 * 讀取并顯示圖片的線程

        106 */

        107 class Load_DrawImage extends Thread {

        108 int x, y;

        109 int imgIndex = 0;

        110

        111 public Load_DrawImage(int x, int y) {

        112 this.x = x;

        113 this.y = y;

        114 }

        115

        116 public void run() {

        117 while (true) {

        118 Canvas c = sfh.lockCanvas(new Rect(this.x, this.y, this.x

        119 + imgWidth, this.y + imgHeight));

        120 Bitmap bmImg = BitmapFactory.decodeResource(getResources(),

        121 imgList.get(imgIndex));

        122 c.drawBitmap(bmImg, this.x, this.y, new Paint());

        123 imgIndex++;

        124 if (imgIndex == imgList.size())

        125 imgIndex = 0;

        126

        127 sfh.unlockCanvasAndPost(c);// 更新屏幕顯示內容

        128 }

        129 }

        130 };

        131

        132 /**

        133 * 只負責繪圖的線程

        134 */

        135 class DrawImage extends Thread {

        136 int x, y;

        137

        138 public DrawImage(int x, int y) {

        139 this.x = x;

        140 this.y = y;

        141 }

        142

        143 public void run() {

        144 while (true) {

        145 if (bitmap != null) {//如果圖像有效

        146 Canvas c = sfh.lockCanvas(new Rect(this.x, this.y, this.x

        147 + imgWidth, this.y + imgHeight));

        148

        149 c.drawBitmap(bitmap, this.x, this.y, new Paint());

        150

        151 sfh.unlockCanvasAndPost(c);// 更新屏幕顯示內容

        152 }

        153 }

        154 }

        155 };

        156

        157 /**

        158 * 只負責讀取圖片的線程

        159 */

        160 class LoadImage extends Thread {

        161 int imgIndex = 0;

        162

        163 public void run() {

        164 while (true) {

        165 bitmap = BitmapFactory.decodeResource(getResources(),

        166 imgList.get(imgIndex));

        167 imgIndex++;

        168 if (imgIndex == imgList.size())//如果到盡頭則重新讀取

        169 imgIndex = 0;

        170 }

        171 }

        172 };

        173}


        上一頁 1 2 下一頁

        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 永和县| 开封县| 龙里县| 衡南县| 安丘市| 武平县| 宝应县| 墨竹工卡县| 天峨县| 岢岚县| 邵武市| 延边| 衡阳市| 岐山县| 轮台县| 曲沃县| 左云县| 南投县| 板桥市| 华坪县| 台南县| 绿春县| 北宁市| 昌江| 梁河县| 姚安县| 六安市| 三门县| 肃南| 金堂县| 永康市| 景洪市| 于都县| 贵南县| 云梦县| 尉犁县| 丹阳市| 许昌县| 温宿县| 任丘市| 饶河县|