简体   繁体   English

将图像传递到另一个活动

[英]Passing an image to another activity

I have an image stored on the hard drive and want to move to another activity. 我有一个存储在硬盘上的图像,想要移动到另一个活动。

In the main activity, the path that I put is as follows: 在主要活动中,我输入的路径如下:

String address = "/ Dir_Imagen / nombre.png";

On the secondary activity, once I pick up the dir, put: 在辅助活动中,一旦我获取了目录,请输入:

Bitmap icon = BitmapFactory.decodeFile (address);

The problem is that the variable icon, returns me null. 问题是变量图标返回null。

Someone knows what is wrong? 有人知道怎么了吗?

You can actually pass the bitmap object from one activity to the other as it's implementing parcelable: 实际上,您可以在实现可打包时将位图对象从一个活动传递到另一个活动:

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("icon", icon);

Then from the second activity, get the bitmap back with: 然后从第二个活动中,使用以下命令返回位图:

Bitmap icon = (Bitmap) getIntent().getParcelableExtra("icon");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM