Android中话bitmap的简单示例
2010-08-24 05:43:00 来源:WEB开发网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);
}
}
更多精彩
赞助商链接