【发布时间】:2020-05-30 03:41:57
【问题描述】:
我正在使用 Kotlin 前端/Python 后端构建应用程序。我的 python 脚本在 getFilesDir() 目录 (/data/user/0/com.example.inprogress/files/mygraph.png) 下创建了一个 .png 文件。然后我想使用 kotlin 来获取 .png 文件并将其显示在 imageview 上。
我的目标是将位图值分配给我的 imageview id graphId。
我使用下面的代码,但我得到的是空白图像视图,而不是我想要显示的 .png 文件。 请注意,我没有收到任何错误消息。我哪里做错了?
class GraphRes : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_graphres)
var data = intent.extras
var graph = data!!.get("res").toString()
// graph is where the .png file is stored
// graph: /data/user/0/com.example.inprogress/files/mygraph.png
var graphId = ImageView(this)
graphId.setImageBitmap(BitmapFactory.decodeFile(graph))
}
}
【问题讨论】:
标签: android kotlin bitmap android-bitmap