Android Kotlin:从目录中获取图像

问题描述 投票:0回答:1

我正在使用Kotlin前端/ Python后端构建应用程序。我的python脚本在getFilesDir()目录(/data/user/0/com.example.myproject/files/mygraph.png)下创建了一个.png文件。然后,我想使用kotlin来获取.png文件并将其显示在imageview上。

相信我必须使用位图,但不熟悉它,因此非常感谢您的支持。

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

    }
}
android kotlin bitmap android-imageview android-bitmap
1个回答
0
投票

使用BitmapFactory解码文件路径

    val imageView = ImageView(this)
        imageView.setImageBitmap(BitmapFactory.decodeFile(filePath))
© www.soinside.com 2019 - 2024. All rights reserved.