Android 将位图作为位数组发送到下一个活动

Android 将位图作为位数组发送到下一个活动,android,android-activity,bitmap,Android,Android Activity,Bitmap,我正在尝试访问另一个活动(如B)中的图像,该图像正在活动(如A)中捕获。现在,我有两个选择: 1. Save to sd card and then access in activity B through the filepath. But, time taken to save is higher in some cases, probably because of higher image size. 2. Send the bit array through inte

我正在尝试访问另一个活动(如B)中的图像,该图像正在活动(如A)中捕获。现在,我有两个选择:

 1. Save to sd card and then access in activity B through the filepath.
   But, time taken to save is higher in some cases, probably because of higher 
   image size.

 2. Send the bit array through intent.putExtra("imageArray" , data) and access it 
   in activity B through getIntent(). But on surfing net, I found sending bigger 
   bitmap of 1MB or more is a bad practise but didn't find anything with regards to 
     bitarray.
有人能告诉我哪个选项更好吗?将更大尺寸的位图作为bitArray发送到另一个活动是一种糟糕的做法吗

我的要求是:两个活动A和B之间的时间差应该最小。此外,图像应立即加载到活动B中


提前感谢。

如果您使用URL在活动A和活动B中加载图像,您可以使用ion-。它帮助您使用URL显示图片,并缓存您的图像,以便立即再次加载,只需将URL从活动a发送到活动B即可


如果您使用手机摄像头拍摄图像,我会说保存图像是更好的方式,如果您想在将来一次发送多张图片,第二个选项将不好。

您还可以在应用程序空间中使用全局变量(singleton)

例如:

public class YourApplication extends Application
 {
   private static YourApplication singleton;
   Bitmap bitmap; // or any type, byte array
   ....

   public static YourApplication getInstance()
    {
      return singleton;
    }

 }
...
在另一个类中,可以设置并获取此变量“位图”:

YourApplication.getInstance().bitmap = ....; // in Activity A

或者在另一种方法中使用

....( ..., YourApplication.getInstance().bitmap, ...);

将其转换为字节数组,然后再将其添加到intent中,发送出去并解码。@AnikIslamAbhi将图像保存到sd卡需要很多时间,这很烦人。@Naveentamakar这种方法对更大尺寸的图像(如5MB)合适吗?如问题前面所述,人们建议不要将较大尺寸的位图(而不是bitArray)作为意图数据发送。不,我正在活动A中捕获图像并将其加载到活动B中。在这里,缓存对我来说没有多大意义,因为不再加载相同的图像。在活动A中,我集成了摄像头,可以捕获图像,我需要在活动B中显示该图像。我不知道您使用的是什么手机,但在没有您的帮助下,使用摄像头是否可以保存图像?你怎么称呼你的意图?意向意向=新意向(MediaStore.ACTION\u IMAGE\u CAPTURE);intent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(destination));startActivityForResult(意图、请求和图像);我已经在我的应用程序中集成了摄像头,我已经覆盖了图片标签(args),因为我需要在捕获的图像上粘贴标签。现在,我调用本地函数saveImageToExternalStorage()来保存图像。但有时需要。我想用intent.putExtra(“imageArray”,finalImage)来代替它。这是一个好方法吗?我需要该应用程序在高清设备上运行良好,如galaxy S5、Nexus 4、5等图像尺寸更大的设备。
....( ..., YourApplication.getInstance().bitmap, ...);