Domanda

Im using the following code to take a photo in my app, but when I accept the photo, the image gets stretched, but when I navigate away from that page, and towards it again the image resolution is correct however a part of the image is black. my question is how can I correctly display the image without it stretching.

  CameraCaptureTask cam = new CameraCaptureTask();
        cam.Completed += task_Completed;

        cam.Show();



  void task_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            imgProfilePic.ImageSource = bmp;
}

and the xaml is:

 <Button HorizontalAlignment="Center" 
                        toolkit:TurnstileFeatherEffect.FeatheringIndex="2"
                        toolkit:TiltEffect.IsTiltEnabled="True"
                        x:Name="btnprofilepic" 
                        Width="250"
                        HorizontalContentAlignment="Center" 
                        VerticalContentAlignment="Center"
                        MouseLeave="btnprofilepic_MouseLeave" 
                        Tap="imgProfilePic_Tap"
                        Margin="0,20,0,20"
                        Height="200"                            BorderThickness="0"
                        MouseLeftButtonUp="btnprofilepic_MouseLeftButtonUp"
                        MouseLeftButtonDown="btnprofilepic_MouseLeftButtonDown">
                    <Button.Background>
                        <ImageBrush x:Name="imgProfilePic"
                                Stretch="Fill"   />
                    </Button.Background>
                </Button>
È stato utile?

Soluzione

In your xaml make strech = "Uniform" because fill will strech the image according to container ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top