【问题标题】:How to share and save the ImageView from First Activity to Third Activity如何将 ImageView 从第一个 Activity 共享和保存到第三个 Activity
【发布时间】:2017-11-11 05:06:39
【问题描述】:

活动 1:我有一个图像视图,其中设置了从相机和画廊拍摄的图像,并且工作正常。在这个 Activity 中有一个右键单击按钮,它会将您重定向到第二个 Activity。

活动2:在这个活动中我有四个选项

  1. 保存
  2. 分享
  3. 通过 Instagram 分享
  4. 通过 Facebook 分享

活动 3:从上述四个选项中,第三个活动相应地起作用。 现在我不知道如何将第一个活动中拍摄的图像传递给第三个活动。

我的努力:在从相机拍摄的第一张 Activity 图像中:

 Intent i=new Intent(Camera.this,SaveVia.class);
 i.putExtra("image", thumbnail );
 startActivity(i);

在第二个活动中 SaveVia:

Intent intent2 = new Intent(SaveVia.this, Save.class);
Bitmap receiptimage = (Bitmap)getIntent().getExtras().getParcelable("image")
startActivity(intent2);

在名为 Save 的第三个 Activity 中:

Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
       // receipt.setImageBitmap(receiptimage);
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        receiptimage.compress(Bitmap.CompressFormat.PNG, 90, bytes);
        File storagePath = new File(Environment.getExternalStorageDirectory() + "/PhotoAR/");
        storagePath.mkdirs();

        File destination = new File(storagePath, Long.toString(System.currentTimeMillis()) + ".jpg");

        FileOutputStream fo;
        try {
            destination.createNewFile();
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
            Toast.makeText(Save.this,"No Error",Toast.LENGTH_LONG).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(Save.this,"Error Arrived",Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(Save.this,"Error Arrived again",Toast.LENGTH_LONG).show();

【问题讨论】:

标签: android android-intent imageview


【解决方案1】:

@AND 您不需要将位图作为 Parcelable 从一个活动传递。将意图中的文件路径从一个活动传递到另一个活动。

当您捕获图像时,在 onActivityresult 中获取路径并保存该路径。 并重定向那两秒钟的活动。并从该路径显示您的位图。只需 Share Uri from path 在 facebook 和 Instagram 上共享。

【讨论】:

    【解决方案2】:

    我建议使用文件 I/O 将位图保存到磁盘。使用 putExtra 将文件的路径放入您的意图包中,并在您的其他屏幕中重新创建位图。将大型位图放入具有意图的包中可能会导致 TransactionTooLarge 异常。

    看看Getting path of captured image in android using camera intent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多