Android 双缓冲

SurfaceView本来就是采用双缓冲的技术实现的,所以此处只练习View的双缓冲使用


package com.Aina.Android;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;

/**
* com.Aina.Android Pro_Canvas
*
* @author Aina.huang E-mail: 674023920@qq.com
* @version 创建时间:2010 Jun 17, 2010 3:14:33 PM 类说明
*/
public class GameView extends View {

private Bitmap mBitmap = null;
private Bitmap mBitmap2 = null;
private Canvas mCanvas = null;
private Paint mPaint = null;

public GameView(Context context) {
super(context);
mBitmap = ((BitmapDrawable) this.getResources().getDrawable(
R.drawable.img)).getBitmap();
mBitmap2 = Bitmap.createBitmap(320, 480, Config.ARGB_8888);//创建屏幕大小的缓冲区
mCanvas = new Canvas();
mCanvas.setBitmap(mBitmap2);//设置将内容绘制在mBitmap2上面
mPaint = new Paint();
mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);//将图片绘制到缓冲屏幕上面
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(mBitmap2, 0, 0, mPaint);
}

}




package com.Aina.Android;

import android.app.Activity;
import android.os.Bundle;

public class Test_Canvas extends Activity {
/** Called when the activity is first created. */
private GameView gv = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gv = new GameView(this);
setContentView(gv);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值