WEB开发网
开发学院手机开发Android 开发 Android中话bitmap的简单示例 阅读

Android中话bitmap的简单示例

 2010-08-24 05:43:00 来源:WEB开发网   
核心提示:Android中话bitmap的简单示例程序效果:读入bitmap的数据流,解码,Android中话bitmap的简单示例,再画出来:package com.ray.draw;import java.io.InputStream;import android.app.Activity;import android.co

Android中话bitmap的简单示例

程序效果:读入bitmap的数据流,解码,再画出来:

package com.ray.draw;

import java.io.InputStream;

import android.app.Activity;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.os.Bundle;

import android.view.View;

public class TestDrawBitmap extends Activity {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(new myView(this));

}

}

class myView extends View{

public myView(Context context) {

super(context);

}

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

//read the icon.png into buffer

InputStream is = getResources().openRawResource(R.drawable.icon);

//decode

Bitmap mBitmap = BitmapFactory.decodeStream(is);

Paint mPaint = new Paint();

canvas.drawBitmap(mBitmap, 40, 40, mPaint);

}

}

Tags:Android bitmap 简单

编辑录入:coldstar [复制链接] [打 印]
赞助商链接