一、
使用
BitmapFactory
解析图片
} 二、 使用BitmapDrawable解析图片
}
三、 使用 InputStream 和 BitmapDrawable 绘制
}
原文地址: http://www.cnblogs.com/lovewf/archive/2011/11/26/2262775.html
// -->
使用
BitmapFactory
解析图片
public
void
myUseBitmapFactory(Canvas canvas){
//
定义画笔
Paint paint =
new
Paint();
//
获取资源流
Resources rec = getResources();
InputStream in = rec.openRawResource(R.drawable.
haha
);
//
设置图片
Bitmap bitmap =BitmapFactory.decodeStream(in);
//
绘制图片
canvas.drawBitmap(bitmap, 0,20, paint);
} 二、 使用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);
}
三、 使用 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);
}
原文地址: http://www.cnblogs.com/lovewf/archive/2011/11/26/2262775.html
本文介绍了在Android中使用三种不同方法加载图片的过程:通过BitmapFactory直接从输入流解析图片;利用BitmapDrawable结合资源ID获取图片;以及采用InputStream与BitmapDrawable配合的方式进行图片解析。

2407

被折叠的 条评论
为什么被折叠?



