【问题标题】:how to get Bitmap from Textureview and pass it to another activity如何从 Textureview 获取位图并将其传递给另一个活动
【发布时间】:2017-03-19 22:59:57
【问题描述】:

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

这是我的代码:

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

这是另一个活动代码:

 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
        }
    }

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

【问题讨论】:

    标签: c# android visual-studio camera textureview


    【解决方案1】:

    在你的点击事件中你应该

     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
    

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多