Android Kotlin: fetching image from directory

扶醉桌前 提交于 2020-06-06 08:34:05

问题


I am building an app with Kotlin frontend/Python backend. My python script creates a .png file under getFilesDir() directory (/data/user/0/com.example.myproject/files/mygraph.png). I then want to use kotlin to fetch the .png file and display it on imageview.

Believe I have to use Bitmap but am not familiar with it so your support is much appreciated.

class Graph : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_graph)

        val dir = "/data/user/0/com.example.myproject/files/mygraph.png"
        //Bitmap function

    }
}

回答1:


Use BitmapFactory to decode file path

    val imageView = ImageView(this)
        imageView.setImageBitmap(BitmapFactory.decodeFile(filePath))


来源:https://stackoverflow.com/questions/62090164/android-kotlin-fetching-image-from-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!