在Kotlin的两个活动之间传输位图 [英] transfer bitmap between two activities in Kotlin

查看:107
本文介绍了在Kotlin的两个活动之间传输位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在stackoverflow中使用java有一些答案,但是我无法将其转换为kotlin代码.我是科特林的新手.请告诉我如何使用Intent将位图数据从一个活动转移到另一个活动

There are some answers using java in stackoverflow but i am unable to convert it into kotlin code. I am new to kotlin. Please tell me how to transfer bitmap data from one activity to another using Intent

推荐答案

在开始活动时,需要将位图作为额外的参数传递给intent.

You need to pass the bitmap as an extra argument to the intent while starting the activity.

val intent = new Intent(this, NewActivity::class.java)
intent.putExtra("BitmapImage", bitmap)
startActivity(intent);

并将其检索为:

val bitmap = this.intent?.getParcelableExtra("BitmapImage") as Bitmap

我只是将代码此处转换为kotlin.您应该使用Android Studio将Java代码转换为Kotlin.

I simply translated the code Here to kotlin. You should use Android Studio to translate Java code to Kotlin.

这篇关于在Kotlin的两个活动之间传输位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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