2019独角兽企业重金招聘Python工程师标准>>>
package com.gavin;
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;
import android.view.WindowManager;
/**
* 测试双缓冲
*
* 先通过setBitmap()将绘制的所有图片绘制到一个bitmap上,
* 然后再调用drawbitmap()绘制这个bitmap显示到屏幕上
* 2013-4-6
*/
public class DoubleBffer extends View
{
private Bitmap mBitmapQQ;
private Paint mPaint;
/** 创建一个缓冲区 */
private Bitmap mscBitmap;
private Canvas mCanvas;
public DoubleBffer(Context context)
{
super(context);
mBitmapQQ = ((BitmapDrawable) getResources().getDrawable(R.drawable.qq)).getBitmap();
WindowManager manager=(WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
int width=manager.getDefaultDisplay().getWidth();
int height=manager.getDefaultDisplay().getHeight();
/** 创建屏幕大小的缓冲区 */
mscBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
mCanvas = new Canvas();
/** 设置将内容绘制在mscBitmap上 */
mCanvas.setBitmap(mscBitmap);
mPaint = new Paint();
/** 将mBitmapQQ绘制到mscBitmap上 */
mCanvas.drawBitmap(mBitmapQQ, 0, 0, mPaint);
//第二张图片绘制
int secbitmapStartY=mBitmapQQ.getHeight();
}
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
/**将mscBitmap显示到屏幕上*/
canvas.drawBitmap(mscBitmap, 0, 0, mPaint);
}
}