Xamarin Texture Camera Image Size

I created an application that feeds data from a camera to allow the user to take a picture, something like SnapChat. but there is a mistake, whenever I take a picture, I send it to another activity to show it, all is well up to this point. But when I go to the Back tab of the Activity it seems like the texture view size has changed.

I took some screenshots to show you guys

This picture shows the thread (Firts Activity) and then the result of the image (second activity)

Image 1

But this happens when you return to active activity:

Image 2

Why is this happening?

this is the code i am using:

Android.Hardware.Camera _camera;
        TextureView _textureView;
        Button TakePictureBtn;
        Bitmap UserPicture;
        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)
        {
            _camera.TakePicture(null, null, this);         
        }

        public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
        {
            _camera = Android.Hardware.Camera.Open();
            Android.Hardware.Camera.Parameters param = _camera.GetParameters();
            IList<Android.Hardware.Camera.Size> supportedSizes = param.SupportedPictureSizes;
            Android.Hardware.Camera.Size sizePicture = supportedSizes[10];
            param.SetPictureSize(sizePicture.Width, sizePicture.Height);
            _camera.SetParameters(param);
            var previewSize = _camera.GetParameters().PreviewSize;
            _textureView.LayoutParameters = 
                new FrameLayout.LayoutParams(h, w, GravityFlags.Center);
            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            _textureView.Rotation = 90.0f;
        }

        public bool OnSurfaceTextureDestroyed(Android.Graphics.SurfaceTexture surface)
        {
            _camera.StopPreview();
            _camera.Release();

            return true;
        }
        public void OnSurfaceTextureSizeChanged(Android.Graphics.SurfaceTexture surface, int width, int height)
        {
            // camera takes care of this
        }
        public void OnSurfaceTextureUpdated(Android.Graphics.SurfaceTexture surface)
        {

        }

      

It is important to say that if I make another picture of this wrong activity, the second activity shows a good picture (as always) and if I go back to flirting, then it works well again, but if I take another one and I come back bad again , etc.

Also I would like to say that Im using AlcaltelPOP2 to debug my application, but when I use another phone (Asus) the Stream looks weird, for example if the gravity line is not working!

Finally, if you notice that the black Gap at the top of the second activity is larger than the first, this is the axml code.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="-30dp"
        android:id="@+id/imageView1" />
    <Button
        android:id="@+id/BtnSendPicture"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="25dp"
        android:layout_marginBottom="25dp"
        android:background="@drawable/SendButton" />
</FrameLayout>

      

It's easy to say that it has to do with the line android:layout_marginBottom="-30dp"

, but the point is, if I erase this line of code, then a little gray line appears in the bootome, why is this happening since the image has a line

android:layout_width="fill_parent"
android:layout_height="fill_parent"

      

Thank.

0


source to share





All Articles