问题
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