一、 使用BitmapFactory解析图片
02 |
public void myUseBitmapFactory(Canvas canvas){ |
04 |
Paint paint = new Paint(); |
06 |
Resources rec = getResources(); |
07 |
InputStream in = rec.openRawResource(R.drawable.haha); |
09 |
Bitmap bitmap =BitmapFactory.decodeStream(in); |
11 |
canvas.drawBitmap(bitmap, 0 , 20 , paint); |
二、 使用BitmapDrawable解析图片
02 |
public void myUseBitmapDrawable(Canvas canvas){ |
04 |
Paint paint = new Paint(); |
06 |
Resources rec = getResources(); |
08 |
BitmapDrawable bitmapDrawable = (BitmapDrawable) rec.getDrawable(R.drawable.haha); |
10 |
Bitmap bitmap = bitmapDrawable.getBitmap(); |
12 |
canvas.drawBitmap(bitmap, 20 , 120 ,paint); |
三、 使用InputStream和BitmapDrawable绘制
02 |
public void myUseInputStreamandBitmapDrawable(Canvas canvas){ |
04 |
Paint paint = new Paint(); |
06 |
Resources rec = getResources(); |
08 |
InputStream in = rec.openRawResource(R.drawable.haha); |
10 |
BitmapDrawable bitmapDrawable = new BitmapDrawable(in); |
12 |
Bitmap bitmap = bitmapDrawable.getBitmap(); |
14 |
canvas.drawBitmap(bitmap, 100 , 100 ,paint); |