代码之家  ›  专栏  ›  技术社区  ›  Aastha Doshi

如何将ImageView从第一个活动共享并保存到第三个活动

  •  2
  • Aastha Doshi  · 技术社区  · 8 年前

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

    1. 拯救
    2. 共有
    3. 通过Instagram分享

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

    我的努力:在从摄像机拍摄的第一张活动图片中:

     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);
    

    在第三个名为“保存”的活动中:

    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();
    
    2 回复  |  直到 8 年前
        1
  •  2
  •   Nirav Shah    8 年前

    @和

    当您拍摄图像时,获取路径 onActivityresult 并保存该路径。 并重定向这两秒钟的活动。从该路径显示位图。只是 来自路径的共享Uri 在脸书和Instagram上分享。

        2
  •  1
  •   Marc    8 年前

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

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