1、使用BitmapFactory解析图片 canvas
// --> 使用BitmapFactory解析图片 学习
public void myUseBitmapFactory(Canvas canvas){ spa
// 定义画笔 code
Paint paint = new Paint(); 图片
// 获取资源流 资源
Resources rec = getResources(); get
InputStream in = rec.openRawResource(R.drawable.haha); it
// 设置图片 map
Bitmap bitmap =BitmapFactory.decodeStream(in); im
// 绘制图片
canvas.drawBitmap(bitmap, 0,20, paint);
2、使用BitmapDrawable解析图片
// --> 使用BitmapDrawable解析图片
public void myUseBitmapDrawable(Canvas canvas){
// 定义画笔
Paint paint = new Paint();
// 得到资源
Resources rec = getResources();
// BitmapDrawable
BitmapDrawable bitmapDrawable = (BitmapDrawable) rec.getDrawable(R.drawable.haha);
// 获得Bitmap
Bitmap bitmap = bitmapDrawable.getBitmap();
// 在画板上绘制图片
canvas.drawBitmap(bitmap, 20,120,paint);
3、使用InputStream和BitmapDrawable绘制
// --> 使用InputStream和BitmapDrawable解析图片
public void myUseInputStreamandBitmapDrawable(Canvas canvas){
// 定义画笔
Paint paint = new Paint();
// 得到资源
Resources rec = getResources();
// InputStream获得资源流
InputStream in = rec.openRawResource(R.drawable.haha);
// BitmapDrawable 解析数据流
BitmapDrawable bitmapDrawable = new BitmapDrawable(in);
// 获得图片
Bitmap bitmap = bitmapDrawable.getBitmap();
// 绘制图片
canvas.drawBitmap(bitmap, 100, 100,paint);