This commit is contained in:
sloop
2016-02-03 01:56:43 +08:00
parent e0e89b3ded
commit 40f2013f22

View File

@@ -246,6 +246,7 @@ public void drawPicture (Picture picture, RectF dst)
InputStream is = mContext.getResources().openRawResource(R.drawable.bitmap);
BitmapDrawable drawable = new BitmapDrawable(is);
Bitmap bitmap = drawable.getBitmap();
is.close();
// 第2种
BitmapDrawable drawable = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.bitmap);
@@ -258,6 +259,7 @@ public void drawPicture (Picture picture, RectF dst)
InputStream is = mContext.getResources().openRawResource(R.raw.bitmap);
BitmapDrawable drawable = new BitmapDrawable(is);
Bitmap bitmap = drawable.getBitmap();
is.close();
```
**assets:**
@@ -267,6 +269,7 @@ public void drawPicture (Picture picture, RectF dst)
InputStream is = mContext.getAssets().open("bitmap.png");
BitmapDrawable drawable = new BitmapDrawable(is);
bitmap = drawable.getBitmap();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
@@ -284,6 +287,7 @@ public void drawPicture (Picture picture, RectF dst)
// 此处省略了获取网络输入流的代码
BitmapDrawable drawable = new BitmapDrawable(is);
Bitmap bitmap = drawable.getBitmap();
is.close();
```
> **注意由于网络涉及的内容比较多例如访问延时读取延时不能在主线程运行异步回调http与https网速影响等等等一系列问题不是本文在重点故略过有兴趣请自行查阅。**