BitmapFactory

前回は、Bitmapをファイルから読み込んだが、今回はdrawableリソースから読み込む・・・。
前回同様、BitmapFactoryで読み込む・・・。

BitmapFactory | Android Developers

activity_main.xmlには、

imageview1・・・。

MainActivity.javaは、

今回は、BitmapFactory.decodeResourceでR.drawable.testの画像を読み込んでbitmapに・・・。
第1引数にはResourcesを渡す必要があるので、getResourcesで渡す・・・。
あとは、前回と同様にimageView1.setImageBitmapでセット・・・。

f:id:BG1:20161212215212p:plain

適当にdrawableのどれかのフォルダにtest.pngを・・・。

f:id:BG1:20161212215245p:plain

こんな風に表示された・・・。
まあこっちのほうがファイルよりは簡単・・・。

Sample/android/BitmapFactory/BitmapFactory/src/BitmapFactory at master · bg1bgst333/Sample · GitHub