Android Kotlin:从目录获取图像 [英] Android Kotlin: fetching image from directory

查看:488
本文介绍了Android Kotlin:从目录获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

    }
}

推荐答案

使用BitmapFactory解码文件路径

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

这篇关于Android Kotlin:从目录获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆