我如何将从我的自定义相机应用程序中拍摄的图像传输到另一个活动中的imageView?我已经使用了 camera2 API

问题描述 投票:0回答:1

发送活动中的代码。

        @Override
        public void onImageAvailable(ImageReader reader) {
            Image image = null;
            image = imageReader.acquireLatestImage();

            ByteBuffer byteBuffer = image.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[byteBuffer.capacity()];
            byteBuffer.get(bytes);
            //code for sending the image to another activity

            Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
            Intent intent = new Intent(MainActivity.this, Main2Activity.class);
            intent.putExtra("bitmap",bitmap);

            try {
                save(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (image != null) {
                    image.close();
                }
            }

        }
    };

在接收活动的代码。

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    imageView = findViewById(R.id.image);

    Intent intent = getIntent();
    Bitmap bitmap = intent.getParcelableExtra("bitmap");

    imageView.setImageBitmap(bitmap);


}

我也试过很多其他方法,但都没有用。任何帮助都将是非常感激的.请大家帮忙!

android android-studio android-intent android-imageview android-camera2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.