gpt4 book ai didi

android - 存储,然后将图像从相机发送到其他 Activity

转载 作者:太空狗 更新时间:2023-10-29 14:16:14 25 4
gpt4 key购买 nike

嗨,在我的页面中,有三个选项可以使图片显示在另一个 Activity 中。选项一存储卡、相机、图像的水平 ListView 。用户可以从中选择什么,但图像应该显示在下一个 Activity ImageView 中。请指导我做进一步!我只是打开相机和存储卡,然后我不知道如何将它发送到下一个 Activity 。

最佳答案

基本上,您需要使用 Intent 将图像的信息传递给下一个 Activity 。

你应该使用:

Intent intent = new Intent(firstActivity.this, secondActivity.class);
intent.putExtra("fileName","SEE_BELOW");
startActivity(intent);

选项 A:如果您使用的是来自 SD 卡的图像 - 将 SEE_BELOW 替换为图像路径的实际字符串。

选项 B:如果您从 ListView 获取图像 - 使用 onItemSelected 方法中的 arg2 获取列表中选定的位置并从那里拉取图像,将其保存到 SD ,并像选项 A 一样发送字符串路径。

选项 C:如果您从相机获取图像 - 我会将图像保存到 SD,然后像选项 A 一样通过 Intent 发送字符串路径。

现在,在您的 SecondActivity 中,您调用的 onCreate 方法中:

Intent intent = getIntent();
String image = intent.getStringExtra("fileName");

现在在您的 image 变量中您有图像的地址 - 只需将它设置到您的 imageView 即可!

关于android - 存储,然后将图像从相机发送到其他 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21822891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com