如何从 Textureview 获取位图并将其传递给另一个 activity

how to get Bitmap from Textureview and pass it to another activity

我的纹理视图上有一个相机流,还有一个拍照按钮,我正在尝试投射纹理视图中的任何内容并将其发送到另一个 activity。

这是我的代码:

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);
        _textureView = FindViewById<TextureView>(Resource.Id.textureView);
        _textureView.SurfaceTextureListener = this;
        TakePictureBtn = FindViewById<Button>(Resource.Id.takePhotoButton);
        TakePictureBtn.Click += TakePicture_Click;

    }

    private void TakePicture_Click(object sender, EventArgs e)
    {
        Bitmap Photo;
        Photo = _textureView.GetBitmap(640,480);
        Intent PictureActivity = new Intent(this, typeof(PictureActivity));
        PictureActivity.PutExtra("Photo", Photo);
        this.StartActivity(PictureActivity);
    } 

这是另一个 activity 代码:

 public class PictureActivity : Activity
    {
        ImageView Photo;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.PictureActivity);
            Photo = FindViewById<ImageView>(Resource.Id.imageView1);
            Photo.SetImageBitmap((Bitmap)Intent.GetParcelableExtra("Photo"));
            // Create your application here
        }
    }

但是当我按下按钮时没有任何反应,这是正确的方法吗? 谢谢

在你的点击事件中你应该

 private void TakePicture_Click(object sender, EventArgs e)
        {
            _camera.TakePicture(null, null, this);         
        }

然后添加:

public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
        {
            _camera.StopPreview();
            Bitmap picture = BitmapFactory.DecodeByteArray(data, 0, data.Length);
            Intent PictureActivity = new Intent(this, typeof(PictureActivity));
            PictureActivity.PutExtra("Photo", picture);
            this.StartActivity(PictureActivity);
            _camera.StartPreview();
        }

别忘了:

 public class Activity1 : Activity, TextureView.ISurfaceTextureListener, IPictureCallback