How to find that captured image comes from front camera or rear camera?

Hello,
I am beginner in xamarin and i want to set the scenario that when image comes from camera and check the conditions that when image comes from front camera then we have to flip that image and if comes from back camera then its remain as it is.
I have a solutions to flip the image but i can not find that the image comes from front camera or rear.
Please give some suggestions, if any one resolve this kind of issues.

Best Answer

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited September 19

    Use Xam.Plugin.Media plugin to take a photo and set the RotateImage property when taking photos.

    //Front Camera
    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        Directory = "Test",
        SaveToAlbum = true,
        CompressionQuality = 75,
        CustomPhotoSize = 50,
        PhotoSize = PhotoSize.MaxWidthHeight,
        MaxWidthHeight = 2000,
    
        //Front
        //DefaultCamera = CameraDevice.Front,
        //RotateImage = true
    });
    
    //Back Camera
    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        ...
    
        //Back
        DefaultCamera = CameraDevice.Rear,
        RotateImage = false
    });
    

    Tutorial and Sample code.
    https://github.com/jamesmontemagno/MediaPlugin

  • DiptejThakkarDiptejThakkar Member ✭✭

    @Jarvan Thanks for your reply.
    when set default as rear camera and user change to front that time its difficult to identify that user open front camera or not because in IOS front camera always flip the image. so we dont want to flip that. i have to save as it is. so we have to reflip(means flip again) and save.

    In this code there are not having any flip change code. there are only rotation code. so can you guide me, how can i flip image ?

  • JarvanJarvan Member, Xamarin Team Xamurai

    Use GetStreamWithImageRotatedForExternalStorage method to get stream with image orientation rotated

    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions{..});
    
    var stream = file.GetStreamWithImageRotatedForExternalStorage();
    

    Refer to:
    https://forums.xamarin.com/discussion/138840/image-taking-with-the-camera-is-crooked

  • DiptejThakkarDiptejThakkar Member ✭✭

    @Jarvan GetStreamWithImageRotatedForExternalStorage this is not work to flip image. please share me another solutions.
    I am trying to use SFimageeditor but there are also some of the issues that its not flip image in code behind. if you have some of the experience on it then you may also guide me for that.

  • DiptejThakkarDiptejThakkar Member ✭✭

    @Jarvan I used

    imgEditor.Source = ImageSource.FromStream(() => stream);
    imgEditor.Flip(FlipDirection.Horizontal);
    imgEditor.Save();

    this image editor is SFimageEditor and its not working flip in code behind

Sign In or Register to comment.