简体   繁体   English

如何在Windows Phone中实现选择照片功能

[英]how to implement choose photo feature in windows phone

I am working on an app, it requires to choose background image from gallery. 我正在开发一个应用程序,它需要从图库中选择背景图像。 For this I am implementing same functionality as Choose Photo feature in Windows phone 8.1 (to set background image), 为此,我实现了与Windows phone 8.1 Choose Photo功能相同的功能(用于设置背景图像),

I have tried this: 我已经试过了:

xaml: XAML:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Name="contentPanel">
        <ScrollViewer Name="scrl"  HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Opacity="0.3">

        </ScrollViewer>
        <ScrollViewer Name="scrlView" Height="500" Width="300" BorderBrush="Red" BorderThickness="1" Background="Transparent">

        </ScrollViewer>
        <Image Name="mtpImg" Stretch="Fill" />
    </Grid>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar Mode="Minimized">
        <shell:ApplicationBarIconButton IconUri="Assets\ApplicationIcon.png" Click="gallery_click" Text="gallery"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

C#: C#:

    private void gallery_click(object sender, EventArgs e)
    {
        PhotoChooserTask chooser = new PhotoChooserTask();
        chooser.Completed += gallery_Completed;
        chooser.Show();
    }

    private void gallery_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            Image img = new Image();
            BitmapImage tmpBitmap = new BitmapImage();
            tmpBitmap.SetSource(e.ChosenPhoto);
            img.Source = tmpBitmap;
            scrl.Content = img;
        }
    }

Problem: how do I set opacity=1 for image showing inside scrlView ScrollViewer? 问题:如何为scrlView ScrollViewer内部显示的图像设置opacity=1

try this for setting opacity as 1: 尝试将此设置为1:

private void gallery_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        Image img = new Image();
        BitmapImage tmpBitmap = new BitmapImage();
        tmpBitmap.SetSource(e.ChosenPhoto);
        img.Source = tmpBitmap;
        scrl.Content = img;
        scrl.Opacity = 1.0;
    }
}

If You want to set image in Image control with Border You can try this: 如果要在带有边框的图像控件中设置图像,可以尝试以下操作:

XAML: XAML:

<Grid Grid.Row="0" Name="contentPanel">
    <Border BorderBrush="Red" Height="500" Width="300" BorderThickness="1">
        <Image Name="mtpImg" Stretch="Fill" Height="500" Width="300"/>
    </Border>
</Grid>

CS: CS:

PhotoChooserTask chooser;
public TaskPage()
{
    InitializeComponent();
    chooser = new PhotoChooserTask();
    chooser.Completed += gallery_Completed;
}

private void gallery_click(object sender, EventArgs e)
{
    chooser.Show();
}

private void gallery_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        BitmapImage tmpBitmap = new BitmapImage();
        tmpBitmap.SetSource(e.ChosenPhoto);
        mtpImg.Source = tmpBitmap;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM